0

我用 C++ 编写了一个函数,它在容器中获取“项目”。我需要将这些变量放在表格中,但是无论我做什么,脚本总是会覆盖表格的第一个单元格。我正在使用 Lua 5.0

Container *box = dynamic_cast<Container*>(item);
        if(box)
        {

            lua_newtable(L);
            int top = lua_gettop(L);
            int n = box->lcontained.size();

            for(int i = 0; i <= n; i++)
            {  

                Item* karta = box->getItem(i);
                if(karta)
                {

                    setField(L,"slot", i);
                    setField(L,"kartaid", karta->getID());

                    lua_settop(L, top);

                }

            }

        }
4

1 回答 1

0
setField(L,"slot", i);

请记住:Lua 使用基于one的索引。因此,在与 Lua 对话的 C++ 代码中,您也必须使用从 1 开始的索引。所以你需要i+1.

于 2011-11-24T19:57:27.030 回答