Here's a quick helper function for pushing rows into a table
void l_pushtablestring(lua_State* L , char* key , char* value) {
lua_pushstring(L, key);
lua_pushstring(L, value);
lua_settable(L, -3);
}
Here I use a helper function to create a table and pass its function
luaL_loadstring(L, "function fullName(t) print(t.fname,t.lname) end");
lua_pcall(L, 0, 0, 0);
lua_getglobal(L, "fullName");
lua_newtable(L);
l_pushtablestring(L, "fname", "john");
l_pushtablestring(L, "lname", "stewart");
lua_pcall(L, 1, 0, 0);
source
share