save lua-table to lua-script
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Centauri Soldier
- Prole
- Posts: 42
- Joined: Mon May 21, 2012 6:38 am
Re: save lua-table in lua-script
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".
- DaedalusYoung
- Party member
- Posts: 407
- Joined: Sun Jul 14, 2013 8:04 pm
Re: save lua-table in lua-script
Tostring returns true and false on my booleans. It can't return 0 or 1, because 0 is not false.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: save lua-table in lua-script
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
will cause an infinite loop.
Also, it doesn't deal with cycle, so
Code: Select all
local T = {}
T.ref = T
serialize(T)
Help us help you: attach a .love.
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: save lua-table in lua-script
Yikes! I didn't think of that.Robin wrote:it doesn't deal with cycle, sowill cause an infinite loop.Code: Select all
local T = {} T.ref = T serialize(T)
This is incorrect. Try it.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".
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: save lua-table in lua-script
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.xXxMoNkEyMaNxXx wrote:Yikes! I didn't think of that.Robin wrote:it doesn't deal with cycle, sowill cause an infinite loop.Code: Select all
local T = {} T.ref = T serialize(T)
Help us help you: attach a .love.
- Centauri Soldier
- Prole
- Posts: 42
- Joined: Mon May 21, 2012 6:38 am
Re: save lua-table in lua-script
Weird, in my other IDE it returns 0 and 1.This is incorrect. Try it.
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: save lua-table in lua-script
Which one? It should never do that in Lua, unless the tostring function is replaced.Centauri Soldier wrote:Weird, in my other IDE it returns 0 and 1.
Re: save lua-table in lua-script
I guess that's another reason why IDEs are bad.
- Centauri Soldier
- Prole
- Posts: 42
- Joined: Mon May 21, 2012 6:38 am
Re: save lua-table in lua-script
Yeah, it uses it's own version of lua.
Who is online
Users browsing this forum: No registered users and 46 guests