- static char buff[64];
- /* value_tostring also always returns the same pointer */
- int len = snprintf(buff, 63, "[%s] -> ", sglua_tostring(L, key_index));
- snprintf(buff + len, 63 - len, "%s", sglua_tostring(L, value_index));
- return buff;
+ for (int i = 1; i < argc; i++) {
+ if (lua_istable(L, i)) {
+ lua_pushnil(L); /* table nil */
+
+ //lua_next pops the topmost element from the stack and
+ //gets the next pair from the table
+ while (lua_next(L, -1)) { /* table key val */
+ // we need to copy here, as a cast from "Number" to "String"
+ // could happen in Lua.
+ // see remark in the lua manual, function "lua_tolstring"
+ // http://www.lua.org/manual/5.3/manual.html#lua_tolstring
+
+ lua_pushvalue(L, -2); /* table key val key */
+
+ const char *key = lua_tostring(L, -1); /* table key val */
+ const char *val = lua_tostring(L, -1); /* table key */
+
+ XBT_DEBUG("%s => %s", key, val);
+ }
+
+ lua_settop(L, argc); // Remove everything except the initial arguments
+ }
+ }
+
+ return 0;