尝试对一个数字值进行索引。C++和Lua。

我正在尝试编写一种使用 Lua 作为脚本语言的引擎。它给我返回了标题中的错误。

#define el Engine::lua
int vecCreate(lua_State* vm) {
    int argc = el.argc();
    el.createTable();
    if (argc == 0) {
        el.tableAddd("x", 0.0);
        el.tableAddd("y", 0.0);
    } 
    else if (argc == 2) {
        el.tableAddd("x", el.argd());
        el.tableAddd("y", el.argd());
    }
    return 1;
}
void Lua::createTable() {
    lua_createtable(vm, 2, 0);
}
void Lua::tableAddd(string key, double val) {
    lua_pushstring(vm, key.c_str());
    lua_pushnumber(vm, val);
    lua_settable(vm, -3);
}
double Lua::argd() {
    double res = lua_tonumber(vm, 1);
    lua_pop(vm, 1);
    return res;
}

我是不是做错了什么?整个脚本是这样的:

function draw()
    drawColor(100, 100, 100)
    drawPoly(vecNew(10, 10), vecNew(10, 100), vecNew(100, 100), vecNew(100, 10))
end

是的,我确定问题出在 draw 函数上。

点赞
用户3080142
用户3080142
Nevermind, I've just pushed a table on the stack in `vecCreate` before getting the arguments

没问题,我在 vecCreate 中获取参数之前在栈上推入了一个表格。

2014-02-04 17:38:40