Skip to content

The LuaReference Object

David Siaw edited this page Jan 22, 2015 · 3 revisions

Under most circumstances, you do not have to use this object directly. Actually, under almost all circumstances, unless you are trying to implement functionality that the library does not provide; like a function with variadic templates (which I believe is a rather bad idea) in C++. If you wish to have any dynamic features, you are better off implementing them inside Lua, and exposing only a non-dynamic interface to C++.

The LuaReference object is the object that LuaTable, LuaCoroutine, LuaFunction<SIGNATURE> and LuaUserdata inherit from. It is the basis of LuaCppInterface's reference objects. The LuaReference object carries with it the lua_State* of the Lua object that created it. Therefore, as long as a LuaReference to a Lua object lives, the context will NEVER DIE.

This is a double-edged sword. It means that you will never have to worry about your Lua state dying under you, but it also means that if you wish to unload a Lua script completely, you have to ensure that all your Lua objects are out of scope.

Clone this wiki locally