Jump to content

ref / deref


Recommended Posts

And for what actually are general functions ref and deref ?

piece from source..

int CLuaFunctionDefs::Reference ( lua_State* luaVM ) 
{ 
    int iArgument1 = lua_type ( luaVM, 1 ); 
    if ( iArgument1 == LUA_TTABLE || iArgument1 == LUA_TFUNCTION || 
        iArgument1 == LUA_TUSERDATA || iArgument1 == LUA_TTHREAD || 
        iArgument1 == LUA_TLIGHTUSERDATA ) 
    { 
        int iPointer = lua_ref ( luaVM, 1 ); 
        lua_pushnumber ( luaVM, iPointer ); 
        return 1; 
    } 
    lua_pushboolean ( luaVM, false ); 
    return 1; 
} 
  
  
int CLuaFunctionDefs::Dereference ( lua_State* luaVM ) 
{ 
    if ( lua_type ( luaVM, 1 ) == LUA_TNUMBER ) 
    { 
        int iPointer = static_cast < int > ( lua_tonumber ( luaVM, 1 ) ); 
        lua_getref ( luaVM, iPointer ); 
        return 1; 
    } 
    lua_pushboolean ( luaVM, false ); 
    return 1; 
} 
  

Link to comment

some info found in Auxiliary Lib

int luaL_ref (lua_State *L, int t); 

Creates and returns a reference, in the table at index t, for the object at the top of the stack (and pops the object).

A reference is a unique integer key. As long as you do not manually add integer keys into table t, luaL_ref ensures the uniqueness of the key it returns. You can retrieve an object referred by reference r by calling lua_rawgeti(L, t, r). Function luaL_unref frees a reference and its associated object.

If the object at the top of the stack is nil, luaL_ref returns the constant LUA_REFNIL. The constant LUA_NOREF is guaranteed to be different from any reference returned by luaL_ref.

void luaL_unref (lua_State *L, int t, int ref); 

Releases reference ref from the table at index t (see luaL_ref). The entry is removed from the table, so that the referred object can be collected. The reference ref is also freed to be used again.

If ref is LUA_NOREF or LUA_REFNIL, luaL_unref does nothing.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...