lua-users home
lua-l archive

Re: Lua <-> C++ integration with "unused" stack slots

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


On Friday 05 February 2010, Joshua Jensen wrote:
> LuaPlus (http://luaplus.org) lets you hold onto a Lua object within a
> C++ object:
> 
> LuaObject myDataObj = state->GetGlobal("MyData");
> LuaObject valueObj = myDataObj["Value"];
> 
> The Lua data is stored within the LuaObject itself and does not need the
> Lua stack.
How does this work?
As I can see from LuaPlus, the LuaObject class looks like:
 class LuaObject
 {
 public:
 ....
 private:
 LuaObject* m_next; // only valid when in free list
 LuaObject* m_prev; // only valid when in used list
 #if defined(BUILDING_LUAPLUS)
 lua_TValue m_object;
 #else
 LP_lua_TValue m_object;
 #endif
 LuaState* m_state;
 };
So objects of this class are holding directly the lua_TValue from the Lua 
virtual machine?
How does this interfere with the Lua garbage collector?
I guess the Lua core must have been modified to get this working?
It seems that there are also (LuaPlus-internal?) objects that represent stack 
slots: 
 class LuaStackObject
 {
 ...
 LuaState* m_state; //!< The parent state of this object.
 int m_stackIndex; //!< The stack index representing this object.
 };
In you implementation: would have been the existence of something like my 
function lua_unuse be useful?
It seems that your implementation does also use a lot of internals of the Lua 
core. Do you think that some modifications to the official public Lua C-API 
could be useful to make integration with the C++ object system (i.e. 
constructor/destructor mechanism) easier?
Best regards,
Oliver

AltStyle によって変換されたページ (->オリジナル) /