lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Luiz Henrique de Figueiredo wrote:
> >From: (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
> --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);
    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
    case LUA_T_PROTO:
      // How do I clone a proto ??
    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
      // Error !

How to clone a proto ?