save lua-table to lua-script

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Centauri Soldier
Prole
Posts: 42
Joined: Mon May 21, 2012 6:38 am

Re: save lua-table in lua-script

Post by Centauri Soldier »

At a glance, your serialize function fails to save boolean values correctly. tostring() on a boolean value will return 0 or 1, not "true" or "false".
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: save lua-table in lua-script

Post by DaedalusYoung »

Tostring returns true and false on my booleans. It can't return 0 or 1, because 0 is not false.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: save lua-table in lua-script

Post by Robin »

I'm not sure the way it deals with types it doesn't recognise in a useful manner. It would be better to throw an error in that case, IMO, than just wait to have it blow up at deserialising time.

Also, it doesn't deal with cycle, so

Code: Select all

local T = {}
T.ref = T
serialize(T)
will cause an infinite loop.
Help us help you: attach a .love.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: save lua-table in lua-script

Post by xXxMoNkEyMaNxXx »

Robin wrote:it doesn't deal with cycle, so

Code: Select all

local T = {}
T.ref = T
serialize(T)
will cause an infinite loop.
Yikes! I didn't think of that.
Centauri Soldier wrote:At a glance, your serialize function fails to save boolean values correctly. tostring() on a boolean value will return 0 or 1, not "true" or "false".
This is incorrect. Try it.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: save lua-table in lua-script

Post by Robin »

xXxMoNkEyMaNxXx wrote:
Robin wrote:it doesn't deal with cycle, so

Code: Select all

local T = {}
T.ref = T
serialize(T)
will cause an infinite loop.
Yikes! I didn't think of that.
It's not necessarily problematic. You just have to make sure you only need to serialize acyclic values. ;) If it's intended to be a general use library, make sure you clearly advertise the fact that it doesn't handle cycles.
Help us help you: attach a .love.
User avatar
Centauri Soldier
Prole
Posts: 42
Joined: Mon May 21, 2012 6:38 am

Re: save lua-table in lua-script

Post by Centauri Soldier »

This is incorrect. Try it.
Weird, in my other IDE it returns 0 and 1.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: save lua-table in lua-script

Post by xXxMoNkEyMaNxXx »

Centauri Soldier wrote:Weird, in my other IDE it returns 0 and 1.
Which one? It should never do that in Lua, unless the tostring function is replaced.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: save lua-table in lua-script

Post by raidho36 »

I guess that's another reason why IDEs are bad.
User avatar
Centauri Soldier
Prole
Posts: 42
Joined: Mon May 21, 2012 6:38 am

Re: save lua-table in lua-script

Post by Centauri Soldier »

Yeah, it uses it's own version of lua.
Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests