[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Trying to use serialize

Trying to use serialize

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Shaun Biggs   USA  (644 posts)  [Biography] 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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] 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.
[Go to top] 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,561 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]