I have a method called GetParameter in C. And I want to use it from Lua. This method is going to return some values to Lua again.
The way that Im building the table in C is the most common way:
lua_newtable(L);
for (int i = 0; i < parameters; i++)
{
lua_pushnumber(L,i);
lua_pushstring(L,myParameter);
lua_settable(L,-3);
}
In all examples that I’ve seen, after this, you have to set the result table with lua setGlobal:
//set name for the result
lua_setglobal(ptLuaState, "resultTable");
With this method, I can access to the result table in lua, like this:
GetParameter("V111","V111Parameter")
printTable(resultTable);
Doing this all things goes well, but, there is another way to do this without using setglobal? I’ve tried to do something like:
local mytable=GetParameter("V111","V111Parameter");
but doesnt work. Using global variables is better? how can I get the result table without make the setglobal?
thanks in advance!
Don’t call setglobal and return 1 from your C function. That tells lua there is 1 return value from your function, and your last example will work.