lua-users home
lua-l archive

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


In attempting to grok how to access a Lua table's members from within a C++
callback (via a modified Luna), I came up with this:

	Lua code:

		local a_table = {"apple", "orange"};
		obj:METHOD("blah", a_table);

	C++ code:

extern "C"
{
   #include "ltable.h"
#include "lstate.h"
}

// code omitted

            else if(lua_istable(L, -1))
            {
               const Table* pTable = (Table*)lua_topointer(L, -1);
               const TObject* pString1 =
(TObject*)luaH_getnum((Table*)pTable, 1);
               const TObject* pString2 =
(TObject*)luaH_getnum((Table*)pTable, 2);
               const TObject* pString3 =
(TObject*)luaH_getnum((Table*)pTable, 3);

               const char* psz1 = svalue(pString1);
               const char* psz2 = svalue(pString2);
            }

Now -- is the above code guaranteed to be safe from within a called back
closure for the duration of the callback (i.e., until I return to the Lua
that invoked it)?

--
Quinn