Skip to content

Instantly share code, notes, and snippets.

@Tzeentchful
Created August 10, 2015 03:29
Show Gist options
  • Save Tzeentchful/58c857f3eb9bee0d2012 to your computer and use it in GitHub Desktop.
Save Tzeentchful/58c857f3eb9bee0d2012 to your computer and use it in GitHub Desktop.
void Push2dArrayToLUA(lua_State* _Env, int _array[9][9])
{
lua_createtable(_Env, 9, 0);
for (int t = 1; t < 10; ++t)
{
// Puts key of the first child table on-top of Lua stack
lua_pushnumber(_Env, t);
// Creates child table
lua_createtable(_Env, 0, 9);
for (int i = 1; i < 10; ++i)
{
// Fills the child table from the array
lua_pushinteger(_Env, _array[t - 1][i - 1]);
lua_rawseti(_Env, -2, i);
}
// Push child table into the root table with the key
lua_settable(_Env, -3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment