Cuberite Forum
cIniFile help? - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: cIniFile help? (/thread-845.html)

Pages: 1 2


cIniFile help? - bearbin - 04-05-2013

Does anyone know if you can list the keys inside a section of an ini file using cIniFile? If so, how could you do it?


RE: cIniFile help? - NiLSPACE - 04-05-2013

Maybe this helps: https://code.google.com/p/mc-server/source/browse/trunk/MCServer/Plugins/Core/listgroups.lua?spec=svn1354&r=1354 it shows a list of groups.


RE: cIniFile help? - bearbin - 04-05-2013

Ok, thanks. It relies on that key numbers are just counting up from 0, instead of random numbersTongue

(the dics didn't say what the key number was).


RE: cIniFile help? - xoft - 04-05-2013

Yeah, I really hate that cIniFile interface. But what can I do, if I rewrite everything I hate, there'd be nothing leftTongue

Anyway, feel free to enhance the docs, it's a wiki, after all. I'm trying, from time to time - at least the hook handlers are more or less documented now, but there's just too many classes with too many changes in them.


RE: cIniFile help? - bearbin - 04-06-2013

Maybe we should build a new IniFile class? Or maybe we could even get a nice YAML parser (you can have more nesting) and deprecate the INI files, but keep IniFile in there for the old plugins.


RE: cIniFile help? - xoft - 04-06-2013

An XML parser is planned in the API:
http://www.mc-server.org/support/index.php?do=details&task_id=336
Later on...


RE: cIniFile help? - bearbin - 04-06-2013

Seems sensible Smile


RE: cIniFile help? - NiLSPACE - 04-06-2013

how to insert multiple things in a value? i did this:
Block:SetValue( KeyName, "I", Player:GetName() .. "," .. "Placed" .. "," .. os.date() .. "," .. Player:GetWorld():GetBlock(X, Y, Z) .. "," .. Player:GetWorld():GetBlockMeta(X, Y, Z) )
to store the data and then this:
Player,Broken,Date,BlockID,BlockMeta = Block:GetValue(KeyName, "I")
to get the info but "Player" gets all the data "I" has stored in an ini file and "Broken" gets everything "KeyName" has.


RE: cIniFile help? - bearbin - 04-06-2013

IDK, simplest way is to do what I do, use my split function:

Code:
function split(string, pattern)

    -- Define variables.
    local t = {}  -- NOTE: use {n = 0} in Lua-5.0
    local fpat = "(.-)" .. pattern
    local last_end = 1
    local s, e, cap = string:find(fpat, 1)

    -- Split the string.
    while s do
        if s ~= 1 or cap ~= "" then
            table.insert(t,cap)
        end
        last_end = e+1
        s, e, cap = string:find(fpat, last_end)
    end

    if last_end <= #string then
        cap = string:sub(last_end)
        table.insert(t, cap)
    end

    -- Return the table.
    return t

end

Call it with:

Code:
Player = split(Block:GetValue(KeyName, "I"), ",")

The code is free to use for whatever you like.


RE: cIniFile help? - NiLSPACE - 04-06-2013

and how can i then add something to Broken, Date, BlockID and BlockMeta with that function? i'm not realy good with tables :S