Gammon Forum
Entire forum
MUSHclient
Lua
Nested tables and serialize
Nested tables and serialize
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Shaun Biggs
USA (644 posts) bio
|
Date
| Tue 05 Jun 2007 06:29 AM (UTC) |
Message
| I'm poking around with trying to save some data between sessions for a plugin of mine, and I ran into a wall trying to deal with nested tables. Here's an example of some of the test data I was using:
/temp = {"qwerty","asdfgh","zxvcbn"}
/print( serialize.save("temp", temp))
temp = {}
temp[1] = "qwerty"
temp[2] = "asfdgh"
temp[3] = "zxvcbn" table: 0116D540
/test = { {1,2,3},{4,5,6},{7,8,9} }
/print( serialize.save("test", test))
Run-time error
World: Aardwolf - Balaam
Immediate execution
C:\Program Files\MUSHclient\lua\serialize.lua:116: Invalid name 'test[1]' for table
stack traceback:
[C]: in function 'assert'
C:\Program Files\MUSHclient\lua\serialize.lua:116: in function 'save_item'
C:\Program Files\MUSHclient\lua\serialize.lua:169: in function 'save_item'
C:\Program Files\MUSHclient\lua\serialize.lua:61: in function 'save'
[string "Command line"]:1: in main chunk
The same error is thrown each time I try to use a nested table, no matter what values I try. I know I'm missing something blatantly obvious here, but I can't figure out what that would be. |
It is much easier to fight for one's ideals than to live up to them. | top |
|
Posted by
| David Haley
USA (3,881 posts) bio
|
Date
| Reply #1 on Tue 05 Jun 2007 06:37 AM (UTC) |
Message
| If memory serves this is a small problem in Nick's serialization code. Search for the error message and you'll find it. Then make sure it looks like this:
assert (string.find (name, "^[_%a][_%a%d%.%[%]\"\"]*$")
and not lua_reserved_words [name],
"Invalid name '" .. name .. "' for table")
I get:
[david@thebalrog:~/development/lib-lua/lua5.1/lua]$ lua
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
> require 'serialize'
> test = { {1,2,3},{4,5,6},{7,8,9} }
> print(serialize.save("test", test))
test = {}
test[1] = {}
test[1][1] = 1
test[1][2] = 2
test[1][3] = 3
test[2] = {}
test[2][1] = 4
test[2][2] = 5
test[2][3] = 6
test[3] = {}
test[3][1] = 7
test[3][2] = 8
test[3][3] = 9 table: 0x64c430
>
This might be worth fixing in the stock serialize.lua distribution, actually. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|
Posted by
| Shaun Biggs
USA (644 posts) bio
|
Date
| Reply #2 on Tue 05 Jun 2007 02:02 PM (UTC) |
Message
| Thank you very much. Serialize works beautifully now. Unfortunately, I can't quite release my plugins with this unless it's fixed in the standard distribution as well. I suppose I could put in an error catcher and have instructions on how to fix it. |
It is much easier to fight for one's ideals than to live up to them. | top |
|
Posted by
| David Haley
USA (3,881 posts) bio
|
Date
| Reply #3 on Tue 05 Jun 2007 09:22 PM (UTC) |
Message
| You could also try changing the global serialize table's function to your own, but that's kind of hackish. I think it would be easiest if the standard file got fixed. Or you could distribute a fixed version and ask people to use that one instead until the main one gets fixed. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #4 on Tue 05 Jun 2007 10:20 PM (UTC) |
Message
| I have updated the serialize.lua function as described by David - for version 4.08 onwards.
For the meantime, it is something you could simply incorporate in your plugin, rather than relying on the separate serialize.lua file. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,276 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.