[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Copy Objects between states
- From: erik@... (Erik Hougaard)
- Date: Wed, 25 Nov 1998 11:46:15 +0100
Luiz Henrique de Figueiredo wrote:
>
> >From: erik@hougaard.com (Erik Hougaard)
> >
> >But back to my original question - How do I Clone a lua object -- forget
> >states - how do I actual clone a object ?
>
> Now, that's a FAQ. See http://www.tecgraf.puc-rio.br/lua/faq.html#3.4
> --lhf
But in order for me to do what I need to do, it must be done in C -
otherwise I cannot do it between states!
// This is what I'm thinking - just as a guideline - This code is just
typed in netscape!
void CloneObject(lua_State *from,lua_State *to,lua_Object *Object)
{
TObject *O = luaA_Address(Object);
switch(ttype(O))
{
case LUA_T_NUMBER:
case LUA_T_STRING:
case LUA_T_NIL:
case LUA_T_USERDATA:
// are all easy enough! (I Think!)
getglobal in state A
push state B
setglobal in state B
break;
case LUA_T_PROTO:
// How do I clone a proto ??
break;
case LUA_T_ARRAY:
// Loop Thru all elements in table and push in other state
Create empty table in state B
loop elements in table and push to new table in state B - if type
= array do recursive!
setglobal table
break;
default:
// Error !
break;
}
}
How to clone a proto ?
Erik