简体   繁体   English

试图索引数值。 C ++和Lua

[英]Attempting to index a number value. C++ & Lua

I'm trying to write a kind of engine that uses Lua as a script language. 我正在尝试编写一种使用Lua作为脚本语言的引擎。 It gives me the error in the title. 它给了我标题中的错误。

#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;
}

Am I doing it wrong? 我做错了吗? The whole script is 整个脚本是

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

Yes, I'm sure that the problem is in the draw function 是的,我确定问题出在draw函数中

没关系,我在获取参数之前只是在vecCreate的堆栈上推了一个表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM