小编Dar*_*yrm的帖子

为什么Lua在这段代码中返回一个空表?

编辑:正如我之前评论过的,我的问题是我不能在C中创建一个使用字符串作为键的表.我制作了一个快速测试程序来演示我遇到的问题:

这是它的C++部分:

#include <lua.hpp>
#include <String.h>

BString
LuaTypeToString(lua_State *L, int index, int type)
{
    BString out;
    switch (type)
    {
        case LUA_TSTRING:
        {
            out << "'" << lua_tostring(L, index) << "'";
            break;
        }
        case LUA_TBOOLEAN:
        {
            out << (lua_toboolean(L, index) ? "true" : "false");
            break;
        }
        case LUA_TNUMBER:
        {
            out << (float)lua_tonumber(L, index);
            break;
        }
        default:
        {
            out << lua_typename(L, type);
            break;
        }
    }
    return out;
}


void
DumpLuaTable(lua_State *L, int tableIndex)
{
    lua_pushnil(L);
    printf("\t{ ");
    while (lua_next(L, tableIndex) != 0) …
Run Code Online (Sandbox Code Playgroud)

c++ lua

3
推荐指数
1
解决办法
1167
查看次数

标签 统计

c++ ×1

lua ×1