Page 3 of 3

Re: A Saving Lib?

Posted: Fri Apr 06, 2012 3:32 pm
by Nixola
If the post is the answer at a question that requires a one-word answer, yes (I think)... Anyway, writing 'a_table{}' seems to call the __call field of the metatable of a_table (I didn't know it until a few minutes ago). If you want to write the content of the table you should either create a function that turns a table into a string (or something like that) or find a library that does it for you (like json4lua)

Re: A Saving Lib?

Posted: Fri Apr 06, 2012 4:04 pm
by Robin
Nixola wrote:Anyway, writing 'a_table{}' seems to call the __call field of the metatable of a_table (I didn't know it until a few minutes ago).
f{} is syntactic sugar for f({})
It works with string literals too. (That's how you can write require "something".)

If you try to call a table, it indeed looks at the __call field of the metatable.

Put those two together, and you get the apparent behaviour.

Re: A Saving Lib? [SOLVED]

Posted: Fri Apr 06, 2012 4:07 pm
by Nixola
Thanks Robin

Re: A Saving Lib? [SOLVED]

Posted: Fri Apr 06, 2012 4:30 pm
by Davidobot
I used json it worked perfectly.

Re: A Saving Lib? [SOLVED]

Posted: Sat Apr 07, 2012 10:25 am
by T-Bone
Or, you could just write valid lua syntax to a file with love.filesystem and then just require the file to load it. Like this:

Code: Select all

string = "a = ".. a.. "/n b = ".. b
love.filesystem.write("data.lua", string) 

--to load
require "data"
 
This example works for numbers, but can easily be changed to work with strings and other objects as well, including tables.