这个函数没有打印 fuction int top = lua_gettop(L);
for (int i = top; i >= 1; i--) { // 从栈顶开始打印
int type = lua_type(L, i);
DEBUG_PRINT("[%d] %s", i, lua_typename(L, type));
switch (type) {
case LUA_TSTRING: {
size_t len;
const char* str = lua_tolstring(L, i, &len);
DEBUG_PRINT(" \"%.*s\"", (int)len, str);
break;
}
case LUA_TNUMBER:
if (lua_isinteger(L, i)) {
DEBUG_PRINT(" %lld", (long long)lua_tointeger(L, i));
} else {
DEBUG_PRINT(" %g", lua_tonumber(L, i));
}
break;
case LUA_TBOOLEAN:
DEBUG_PRINT(" %s", lua_toboolean(L, i) ? "true" : "false");
break;
case LUA_TTABLE:
// 打印table简要信息
lua_pushvalue(L, i); // 复制table引用
lua_pushnil(L); // 初始key
DEBUG_PRINT(" {");
while (lua_next(L, -2) != 0) {
// 打印 key-value 对
if (lua_type(L, -2) == LUA_TSTRING) {
DEBUG_PRINT(" [%s] = ", lua_tostring(L, -2));
}
// 简化值打印
if (lua_type(L, -1) == LUA_TSTRING) {
DEBUG_PRINT("'%s'", lua_tostring(L, -1));
} else if (lua_type(L, -1) == LUA_TNUMBER) {
DEBUG_PRINT("%g", lua_tonumber(L, -1));
}
lua_pop(L, 1); // 移出value,保留key
}
DEBUG_PRINT(" }");
lua_pop(L, 1); // 移出table副本
break;
default:
break;
}
}
最新发布