luafar/src/exported.c
HANDLE RegisterObject(lua_State* L)
{
  void *ptr;
  lua_newtable(L);                  //+2: Obj,Tbl
  lua_pushvalue(L,-2);              //+3: Obj,Tbl,Obj
  lua_setfield(L,-2,KEY_OBJECT);    //+2: Obj,Tbl
  ptr = (void*)lua_topointer(L,-1);
  lua_pushlightuserdata(L, ptr);    //+3
  lua_pushvalue(L,-2);              //+4
  lua_rawset(L, LUA_REGISTRYINDEX); //+2
  lua_pop(L,2);                     //+0
  return ptr;
}
// -- an object (any non-nil value) is on stack top;
// -- a new table is created, the object is put into it under the key KEY_OBJECT;
// -- the table is put into the registry, and reference to it is obtained;
// -- the function pops the object and returns the reference;
an object (any non-nil value) is on stack top;
a new table is created, the object is put into it under the key KEY_OBJECT;
the table is put into the registry, and reference to it is obtained;
the function pops the object and returns the reference.
an object ( any non - nil value ) is on stack top ; a new table is created the object is put into it under the key KEY_OBJECT ; the table is put into the registry and reference to it is obtained ; the function pops the object and returns the reference .
HANDLE RegisterObject(lua_State* L)
{
  void *ptr;
  lua_newtable(L);                  
  lua_pushvalue(L,-2);              
  lua_setfield(L,-2,KEY_OBJECT);    
  ptr = (void*)lua_topointer(L,-1);
  lua_pushlightuserdata(L, ptr);    
  lua_pushvalue(L,-2);              
  lua_rawset(L, LUA_REGISTRYINDEX); 
  lua_pop(L,2);                     
  return ptr;
}
HANDLE RegisterObject ( lua_State * L ) { void * ptr ; lua_newtable ( L ) ; lua_pushvalue ( L , -2 ) ; lua_setfield ( L , -2 , KEY_OBJECT ) ; ptr = ( void * ) lua_topointer ( L , -1 ) ; lua_pushlightuserdata ( L , ptr ) ; lua_pushvalue ( L , -2 ) ; lua_rawset ( L , LUA_REGISTRYINDEX ) ; lua_pop ( L , 2 ) ; return ptr ; }
an object (any non-nil value) is on stack top;
 a new table is created, the object is put into it under the key KEY_OBJECT;
 the table is put into the registry, and reference to it is obtained;
 the function pops the object and returns the reference;
an object ( any non - nil value ) is on stack top ; a new table is created the object is put into it under the key KEY_OBJECT ; the table is put into the registry and reference to it is obtained ; the function pops the object and returns the reference ;
//+2: Obj,Tbl //+3: Obj,Tbl,Obj //+2: Obj,Tbl //+3 //+4 //+2 //+0