Reputation: 536
I'm trying to write a kind of engine that uses Lua as a script language. 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
Upvotes: 0
Views: 1638
Reputation: 536
Nevermind, I've just pushed a table on the stack in vecCreate
before getting the arguments
Upvotes: 2