Page 2 of 2
Re: Weird errors
Posted: Tue Nov 30, 2010 7:58 pm
by Denarii
I already have, in the latest LuaGlobal it's _Echos
Re: Weird errors
Posted: Tue Nov 30, 2010 9:59 pm
by tarrant
Heiko wrote:You forgot to specify which table you want to save. The syntax is: table.save( path, myTableThatIwantToSerialize )
The same applies to table.load(). Those are general functions that can be used to serialize any Lua table or restore the data from a file to any given table. When restoring a table from file you need to tell the function which table you want to hold the content as the table name is not part of the file.
in a post you made
here, you said if table isn't specified, then it'll just save everything. i thought that would be easier. or did i misunderstand what you said?
Re: Weird errors
Posted: Wed Dec 01, 2010 2:42 pm
by Heiko
Oh I see. This information is outdated because I've changed Mudlet's script initializations and profile loading code in the meantime. You are right. There used to be a second undocumented function that was intended to be used by Mudlet itself to store all global variables in _G. I've dropped this idea though because of various reasons. I don't remember if this function is still part of LuaGlobal -> please check the source of LuaGlobal.lua Normally, Mudlet's API is never changed to guarantee that old scripts still work on newer releases, but as this function has never been publicly documented, it may have been removed.
In any case I strongly advise against using it because I've changed Mudlet's script loading in the meantime which may lead to very unexpected results if this function is being used.
Today, the recommended approach is to use table.save( filepath, table ).
Re: Weird errors
Posted: Wed Dec 01, 2010 7:38 pm
by Vadi
That'd explain some odd global overwrite issues people were having then, when they were mis-using the function.
Re: Weird errors
Posted: Wed Dec 01, 2010 7:54 pm
by tarrant
Ah, i see. Ok thanks for clarifying.
How do i create this table to save?
Re: Weird errors
Posted: Wed Dec 01, 2010 10:16 pm
by Heiko
You pass a filepath and a reference to a table to table.save() e.g. table.save(getMudletHomeDir().."/myVars.data", tableThatContainsMyPermVariables )
Re: Weird errors
Posted: Wed Dec 01, 2010 11:15 pm
by tarrant
do you mean that i don't need to manually create my own table and add my variables in?
Re: Weird errors
Posted: Thu Dec 02, 2010 7:00 am
by Heiko
No, you can save any table in the global namespace.