Trying to use serialize

Posted by Shaun Biggs on Wed 11 Apr 2007 01:10 AM — 3 posts, 14,936 views.

USA #0
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.
Amended on Wed 11 Apr 2007 01:11 AM by Shaun Biggs
USA #1
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'.
USA #2
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