Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
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.
11,343 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top