在 C 端打印lua- table结构
static void stackDump (lua_State *L) {
int top = mln_lua_gettop(L);
printf("{\n");
lua_pushnil(L);
while (lua_next(L, -2)) {
switch (lua_type(L, -2)) {
case LUA_TSTRING:
printf("%s = ", mln_lua_tolstring(L, -2, 0));
break;
case LUA_TNUMBER:
printf("[%td] = ", lua_tointeger(L, -2));
break;
}
int t = lua_type(L, -1);
switch (t) {
case LUA_TSTRING : {
printf("'%s'", lua_tostring(L, -1));
break;
}
case LUA_TBOOLEAN : {
printf(lua_toboolean(L, -1) ? "true" : "false");
break;
}
case LUA_TNUMBER : {
if (lua_isinteger(L, -1))
printf("%td", lua_tointeger(L, -1));
else
printf("%g", lua_tonumber(L, -1));
break;
}
case LUA_TTABLE: {
stackDump(L);
}break;
default : {
printf("%s", lua_typename(L, t));
break;
}
}
lua_pop(L, 1);
printf(",\n");
}
lua_pop(L, mln_lua_gettop(L) - top);
printf("}\n");
}
复制代码
see