-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to return a table? #64
Comments
It is maybe like this int luafnc(lua_State* L)
{
int nRows = dataTable.NumOfRows();
int nField = dataTable.NumOfFields();
kaguya::State state(L);
kaguya::LuaTable array= state.newTable(nRows);
for (int i = 0; i < nRows; i++)
{
kaguya::LuaTable row= state.newTable(0,nField);
for (int j = 0; j < nField; j++)
{
dataTable.SetRow(i);
row[dataTable.NameOfField(j)] = dataTable.ValueOfField(j);
}
array[i + 1] = row;
}
state.pushToStack(array);
return 1;
} |
in member function, can i write like this?
} |
how can i return a table?
i do not want to create map in c/c++(it use frequency)
now code:(how to change to kaguya)
int nRows = dataTable.NumOfRows();
int nField = dataTable.NumOfFields();
lua_newtable(tolua_S);
int array_index = lua_gettop(tolua_S);
for (int i = 0; i < nRows; i++)
{
lua_newtable(tolua_S);
int result_index = lua_gettop(tolua_S);
for (int j = 0; j < nField; j++)
{
dataTable.SetRow(i);
lua_pushstring(tolua_S, dataTable.NameOfField(j));
lua_pushstring(tolua_S, dataTable.ValueOfField(j));
lua_settable(tolua_S, result_index);
}
lua_settop(tolua_S, result_index);
lua_rawseti(tolua_S, array_index, i + 1);
}
The text was updated successfully, but these errors were encountered: