Page 2 of 7
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:17
by Argh
Result: {testingsave={hello={kitty=cat}}}
So... is GG = {testingsave={hello={kitty=cat}}} the same as GG.testingsave = {hello = {kitty = cat}} (the original test value)? That looks right...
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:19
by aegis
GG['testingsave'] == GG.testingsave
try it with multiple vars in one or more of the tables, make sure it handles that right
...
you don't want strings encased in quotes?
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:24
by Argh
Hmm. Two first-iteration values:
{testingsave={hello={kitty=cat}},foo={bar={barfoo=boo}}}
Original:
GG.testingsave = {hello = {kitty = 'cat'}}
GG.foo = {bar = {barfoo = 'boo'}}
That second one looks like exactly what is needed: GG = { foo={bar={barfoo=boo}}, }
Oops, nvm, wasn't counting brackets lol, there's one too many.
GG = { foo={bar={barfoo=boo}}, }
not
GG = { foo={bar={barfoo=boo}}}, }
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:28
by aegis
Code: Select all
{
testingsave={
hello={
kitty=cat
}
},
foo={
bar={
barfoo=boo
}
}
}
brackets are right, based on "{testingsave={hello={kitty=cat}},foo={bar={barfoo=boo}}}"
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:29
by Argh
Ohhh, it's enclosing the whole thing. OK.
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:29
by aegis
right, because GG is a table. do you want it to put quotes around strings?
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:42
by Argh
Yeah. I just ran into that fun problem.
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:45
by aegis
is that a yes? if so, try this.
Code: Select all
local function dumpTable(tab)
if type(tab) == 'table' then
local tmp = {}
for a, b in pairs(tab) do
table.insert(tmp, a .. '=' .. dumpTable(b))
end
return '{' .. table.concat(tmp, ',') .. '}'
elseif type(tab) == 'string' then
return "'" .. tab .. "'"
else
return tab
end
end
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 04:52
by Argh
Hmm. GG.testingsave == nil
So... um, I guess surround all a's with quotes if not numbers?
Or... GG['testingsave']... shit
Nope.
GG ={['testingsave']={['hello']={['kitty']='cat'}},['foo']={['bar']={['barfoo']='boo'}}}
Both GG.testingsave and GG['testingsave'] return nil
With this function (was going to add math check, but whatever
Code: Select all
local function dumpTable(tab)
if type(tab) == 'table' then
local tmp = {}
for a, b in pairs(tab) do
table.insert(tmp, "['"..tostring(a).."']".. '=' .. dumpTable(b))
end
return '{' .. table.concat(tmp, ',') .. '}'
elseif type(tab) == 'string' then
return "'" .. tab .. "'"
else
return tab
end
end
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:00
by aegis
['testingsave']=
what?
I have no idea why you added that except possibly to break it.
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:03
by Argh
IDK. Sorry, been up since 5AM, I am now officially punch-drunk.
Whatever's going on, the top-level reference doesn't return <table>
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:11
by Argh
Wait, I think I got it... did something really silly
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:13
by aegis
did it possibly have something to do with the only line you changed?
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:15
by Argh
No, and it didn't work, either. I still get a value of nil for GG.testingsave.
This is really amazingly stupid. I did a few things like this before I ended up with the hand-coded recursions.
The problem is, GG.testingsave = {blah = {blahblah = 1}} does not appear to be equivalent to GG = {testingsave = {blah = {blahblah = 1}}}
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:23
by aegis
Code: Select all
> GG = {}
> GG.testingsave = {blah = {blahblah = 1}}
> ZZ = {testingsave = {blah = {blahblah = 1}}}
> print(dumpTable(GG))
{testingsave={blah={blahblah=1}}}
> print(dumpTable(ZZ))
{testingsave={blah={blahblah=1}}}
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:28
by Argh
Hmm. Code in save-file:
GG ={testingsave=2,foo={bar={barfoo=boo}}}
Spring.Echo(GG.testingsave) returns nil
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:31
by aegis
Code: Select all
local function dumpTable(tab)
if type(tab) == 'table' then
local tmp = {}
for a, b in pairs(tab) do
table.insert(tmp, tostring(a) .. '=' .. dumpTable(b))
end
return '{' .. table.concat(tmp, ',') .. '}'
elseif type(tab) == 'string' then
return "'" .. tab .. "'"
else
return tostring(tab)
end
end
added tostring fallback for types that don't concat well
what's GG? does it allow direct assignment? I'm guessing not.
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:34
by Argh
GG's the gadget global table.
Meh. In previous tests (with that ugly iterative hack):
GG.testingsave = {foo = {bar = barfoo}}
Worked both ways. But that code rebuilds it exactly like that.
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:36
by aegis
Code: Select all
for a,b in pairs (GG) do
Spring.SendLuaUIMsg('write_save_file ' .. 'GG.' .. tostring(a) ..'=' .. dumpTable(b))
end
Re: SaveGame v. 0.1
Posted: 23 Jan 2010, 05:39
by Argh
Yeah... that looks like it'll do it.