MX_Master Posted May 21, 2011 Share Posted May 21, 2011 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
DakiLLa Posted May 21, 2011 Share Posted May 21, 2011 Yea, long time ago I was asking same question somewhere here.. Link to comment
MX_Master Posted May 21, 2011 Author Share Posted May 21, 2011 ref is giving `number` pointer to the stack position of var which was placed as first argument? But how to use this `number` reference? ((: Link to comment
Maccer. Posted May 21, 2011 Share Posted May 21, 2011 Probably can't in LUA. It would be very awesome if you could. Lua needs references pretty badly, or at least parameter references. Link to comment
MX_Master Posted May 22, 2011 Author Share Posted May 22, 2011 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now