Discussion:
Serializing Lua State in use with Luabind
Stefan Schwarzbach
2005-05-14 18:20:24 UTC
Permalink
Hello,

I'm using Lua and Luabind for a game development project and therefore I
must be able to serialize the actual "lua world" in my savegame to later
load it and resume at the same position in game as I saved.

I tried to use the Pluto Library, because it should excactly do what I
needed. This library seems to work perfecly, but it has a major missing
feature or problem. The tables luabind creates for storing the lua
classes can't be serialized by pluto. So I cannot save lua instances of
lua classes ( and also instances of c++ classes, but that's another
problem).

So here is my question: Does anyone of you ever tried to serialize a lua
states in combination with luabind? Did you get Pluto working or did you
use another library?

I hope you can help me!

Thanks in advance,
Stefan Schwarzbach
Ben Sunshine-Hill
2005-05-14 18:10:05 UTC
Permalink
Stefan,

That's very interesting. While I've barely ever used luabind, on the
face of it it doesn't seem like Lua tables created by luabind should
be any different than Lua tables created by the Lua API. Would you
mind providing info on how the table was created, and what happened
when you tried to serialize it with Pluto?

Thanks,

Ben Sunshine-Hill
Post by Stefan Schwarzbach
Hello,
I'm using Lua and Luabind for a game development project and therefore I
must be able to serialize the actual "lua world" in my savegame to later
load it and resume at the same position in game as I saved.
I tried to use the Pluto Library, because it should excactly do what I
needed. This library seems to work perfecly, but it has a major missing
feature or problem. The tables luabind creates for storing the lua
classes can't be serialized by pluto. So I cannot save lua instances of
lua classes ( and also instances of c++ classes, but that's another
problem).
So here is my question: Does anyone of you ever tried to serialize a lua
states in combination with luabind? Did you get Pluto working or did you
use another library?
I hope you can help me!
Thanks in advance,
Stefan Schwarzbach
Stefan Schwarzbach
2005-05-14 22:58:36 UTC
Permalink
Well, when I serialize a Lua State with Luabind classes inside, the
following happens:

When I come to the point to serialize the Lua Class Pluto first
serializes the name of the class which function properly. At next he
wants to store some Userdata, no problem. But then he continues storing
the lua table (which represents the lua class, I think), and there he
wants to store a function called __eq (the first element he wants to
store in the table). I get an error in Pluto, because this function
seems to be a C/C++ function from luabind.

I don't know how to solve that problem. Any ideas?

Thanks,
Stefan
Post by Ben Sunshine-Hill
Stefan,
That's very interesting. While I've barely ever used luabind, on the
face of it it doesn't seem like Lua tables created by luabind should
be any different than Lua tables created by the Lua API. Would you
mind providing info on how the table was created, and what happened
when you tried to serialize it with Pluto?
Thanks,
Ben Sunshine-Hill
Post by Stefan Schwarzbach
Hello,
I'm using Lua and Luabind for a game development project and therefore I
must be able to serialize the actual "lua world" in my savegame to later
load it and resume at the same position in game as I saved.
I tried to use the Pluto Library, because it should excactly do what I
needed. This library seems to work perfecly, but it has a major missing
feature or problem. The tables luabind creates for storing the lua
classes can't be serialized by pluto. So I cannot save lua instances of
lua classes ( and also instances of c++ classes, but that's another
problem).
So here is my question: Does anyone of you ever tried to serialize a lua
states in combination with luabind? Did you get Pluto working or did you
use another library?
I hope you can help me!
Thanks in advance,
Stefan Schwarzbach
Ben Sunshine-Hill
2005-05-15 01:38:27 UTC
Permalink
Ahh, I think I know what's going on.

LuaBind is trying to store a metatable for a table, and the metatable
contains an __eq metamethod which is a C-function. Pluto, which has no
way of serializing C functions, thus fails.

Have you tried adding the metatable to the permanents table? Assuming
there's only one metatable per class, this shouldn't be much overhead,
and should work fine. Tell me if you need help with this; I'd very
much like to be aware of interactions between Pluto and binding
libraries like LuaBind.

Ben
Post by Stefan Schwarzbach
Well, when I serialize a Lua State with Luabind classes inside, the
When I come to the point to serialize the Lua Class Pluto first
serializes the name of the class which function properly. At next he
wants to store some Userdata, no problem. But then he continues storing
the lua table (which represents the lua class, I think), and there he
wants to store a function called __eq (the first element he wants to
store in the table). I get an error in Pluto, because this function
seems to be a C/C++ function from luabind.
I don't know how to solve that problem. Any ideas?
Thanks,
Stefan
Post by Ben Sunshine-Hill
Stefan,
That's very interesting. While I've barely ever used luabind, on the
face of it it doesn't seem like Lua tables created by luabind should
be any different than Lua tables created by the Lua API. Would you
mind providing info on how the table was created, and what happened
when you tried to serialize it with Pluto?
Thanks,
Ben Sunshine-Hill
Post by Stefan Schwarzbach
Hello,
I'm using Lua and Luabind for a game development project and therefore I
must be able to serialize the actual "lua world" in my savegame to later
load it and resume at the same position in game as I saved.
I tried to use the Pluto Library, because it should excactly do what I
needed. This library seems to work perfecly, but it has a major missing
feature or problem. The tables luabind creates for storing the lua
classes can't be serialized by pluto. So I cannot save lua instances of
lua classes ( and also instances of c++ classes, but that's another
problem).
So here is my question: Does anyone of you ever tried to serialize a lua
states in combination with luabind? Did you get Pluto working or did you
use another library?
I hope you can help me!
Thanks in advance,
Stefan Schwarzbach
Stefan Schwarzbach
2005-05-15 12:51:58 UTC
Permalink
I don't know how to identify the metatable to list it in the permanent
table.

Here's the call stack from the beginning of the serialization to the
C-function problem:

persistfunction(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
persisttable(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
persistuserdata(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
// Main persist table
persisttable(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
// Start call
pluto_persist(lua_State * L=0x0e674b20, int (lua_State *, const void *,
unsigned int, void *)* writer=0x0060b615, void * ud=0x1027c8f8)

What do I have to do to identify the metatable? I don't get a name from
the that metatable, only from the class table itself and from the
function name.

Greetings,
Stefan
Post by Ben Sunshine-Hill
Ahh, I think I know what's going on.
LuaBind is trying to store a metatable for a table, and the metatable
contains an __eq metamethod which is a C-function. Pluto, which has no
way of serializing C functions, thus fails.
Have you tried adding the metatable to the permanents table? Assuming
there's only one metatable per class, this shouldn't be much overhead,
and should work fine. Tell me if you need help with this; I'd very
much like to be aware of interactions between Pluto and binding
libraries like LuaBind.
Ben Sunshine-Hill
2005-05-15 20:28:44 UTC
Permalink
It should be as easy as using lua_getmetatable() on one of the
objects, and putting the resultant table in the permanents table; all
objects of that class most likely use the same metatable. This is
slightly hackish, since technically it should be possible to grab the
metatable from the LuaBind class registry, but I'm familiar enough
with LuaBind to know how to do that.

Ben
Post by Stefan Schwarzbach
I don't know how to identify the metatable to list it in the permanent
table.
Here's the call stack from the beginning of the serialization to the
persistfunction(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
persisttable(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
persistuserdata(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
// Main persist table
persisttable(PersistInfo_t * pi=0x0006f8f0)
persist(PersistInfo_t * pi=0x0006f8f0)
// Start call
pluto_persist(lua_State * L=0x0e674b20, int (lua_State *, const void *,
unsigned int, void *)* writer=0x0060b615, void * ud=0x1027c8f8)
What do I have to do to identify the metatable? I don't get a name from
the that metatable, only from the class table itself and from the
function name.
Greetings,
Stefan
Post by Ben Sunshine-Hill
Ahh, I think I know what's going on.
LuaBind is trying to store a metatable for a table, and the metatable
contains an __eq metamethod which is a C-function. Pluto, which has no
way of serializing C functions, thus fails.
Have you tried adding the metatable to the permanents table? Assuming
there's only one metatable per class, this shouldn't be much overhead,
and should work fine. Tell me if you need help with this; I'd very
much like to be aware of interactions between Pluto and binding
libraries like LuaBind.
Stefan Schwarzbach
2005-05-16 17:32:13 UTC
Permalink
Okay, I'll give that a try.

I also found the position in LuaBind's open function where the
metatables are created.
But what I'm not sure is, that the meta table I will add to the
permantents table does not contain any data that will be needed when
restoring the Lua state... I hope so

Then I have another question:
In my project, I also must access instances of c++ classes from lua. How
does the serialization of lua functions happen. Could it be a problem to
serialize a lua function which locally calls a function of a c++ class
or simply a c/c++ function? Can you serialize this?

Big Thanks,
Stefan
Post by Ben Sunshine-Hill
It should be as easy as using lua_getmetatable() on one of the
objects, and putting the resultant table in the permanents table; all
objects of that class most likely use the same metatable. This is
slightly hackish, since technically it should be possible to grab the
metatable from the LuaBind class registry, but I'm familiar enough
with LuaBind to know how to do that.
Ben
Ben Sunshine-Hill
2005-05-16 17:51:20 UTC
Permalink
Post by Stefan Schwarzbach
But what I'm not sure is, that the meta table I will add to the
permantents table does not contain any data that will be needed when
restoring the Lua state... I hope so
It seems unlikely that there'd be any stuff that changes.
Post by Stefan Schwarzbach
In my project, I also must access instances of c++ classes from lua. How
does the serialization of lua functions happen. Could it be a problem to
serialize a lua function which locally calls a function of a c++ class
or simply a c/c++ function? Can you serialize this?
The most common situation is the following:

function someluafunc()
somecfunc()
end

in this case, someluafunc does not actually reference the C function
somecfunc. Instead, it references the string "somecfunc", and when it
is executed it looks up the entry in the global table with that key.
So the serializer never even touches the C function somecfunc.

Ben

Loading...