【问题标题】:Attempting to index a number value. C++ & Lua试图索引一个数值。 C++ 和 Lua
【发布时间】:2014-02-05 01:38:40
【问题描述】:

我正在尝试编写一种使用 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

是的,我确定问题出在绘图功能上

【问题讨论】:

  • 只是好奇,您不使用 luabind、SWIG 或 lua-icxx 有什么原因吗?我在同一个程序中将后者与 SWIG 一起使用,它为我节省了大量时间。
  • 是的,原因是 luabind 的提升。对他们所有人来说都是懒惰的。我不想再学习了

标签: c++ lua


【解决方案1】:

没关系,在获取参数之前,我刚刚在 vecCreate 的堆栈中推送了一张表

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 2021-05-15
    • 2016-12-21
    • 1970-01-01
    • 2012-08-01
    • 2016-09-19
    • 1970-01-01
    相关资源
    最近更新 更多