Gammon Forum
Entire forum
MUSHclient
Lua
Trying to use 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
| Wed 11 Apr 2007 01:10 AM (UTC) Amended on Wed 11 Apr 2007 01:11 AM (UTC) by Shaun Biggs
|
Message
| I'm attempting to use serialize to store tables. I can get everything put INTO a variable just fine. It looks great and all, but I can't seem to load it. Please tell me what I'm doing wrong here:
require "serialize"
do
temp = { 1,2,3 }
serialize.save( "temp", temp )
temp = {}
print( loadstring( GetVariable( "temp" ) ) )
for i,v in ipairs(temp) do
print(i,v)
end
end
This will store the temp variable just fine, but the only output is: function: 00D11968 which suggests that loadstring isn't doing much of anything. |
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 Wed 11 Apr 2007 01:51 AM (UTC) |
Message
| loadstring creates a function that when called does whatever the string says to do. So you are missing the step where you actually call the return value of loadstring. See:
http://www.lua.org/manual/5.1/manual.html#pdf-loadstring
Also, IIRC, serialize.save returns the string in which the table has been saved, so you'd still need to actually set the variable 'temp'. |
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 Wed 11 Apr 2007 02:34 AM (UTC) Amended on Wed 11 Apr 2007 02:38 AM (UTC) by Shaun Biggs
|
Message
| I must have copied the wrong serialize.save line down, I had it wright in my script. Encapsulating the loadstring in an Assert did the trick for loading it. This wasn't in the only examples of loadstring I found for serialize though, either in the .lua file itself, or in http://www.gammon.com.au/forum/bbshowpost.php?id=4960 |
It is much easier to fight for one's ideals than to live up to them. | 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.
9,607 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.