lua-users home
lua-l archive

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


Hi,

Is there a way i could access a local lua table in C++

supposedly i am having a lua table such as

local temptable ={}

temptable.status = "UNKNOWN" 
temptable.error = "NONE"
temptable.value = "" 
temptable.info = ""

I would like to access this table and any local lua table from C++. I am able to query the global lua table using the following code. which queries the global lua table perfectly. Is there any identical mechanism avaialble for querying local lua tables dynamically

        lua_getglobal(L, key);
int pos = lua_gettop(L);

lua_pushnil(L);
char temp[150]={0},temp1[150]={0};
int i = 0;
                                                         std::vector<std::string> tableValues;
                  while(lua_next(L, pos) != 0)
{
sprintf(temp1,"%s = %s",lua_tostring(L, -2), lua_tostring(L, -1));
                                                                 tableValues.push_back(temp1);
                                                                  lua_pop(L, 1);
                                                        }

Thanks