More quality of life

This commit is contained in:
Dane Johnson
2021-01-21 11:12:45 -06:00
parent 6f03ed7295
commit 43996eb2e6
6 changed files with 41 additions and 13 deletions

View File

@@ -52,7 +52,10 @@ void Lua::Update(double delta) {
if (HasHook("update")) {
lua_getglobal(L, "update");
lua_pushnumber(L, delta);
lua_call(L, 1, 0);
int err = lua_pcall(L, 1, 0, 0);
if (err != LUA_OK) {
Error();
}
}
#endif // LUA_SCRIPTING
}
@@ -89,7 +92,10 @@ void Lua::LuaKeyHandler(Window *window, int key, int code, int action, int mods)
lua_pushinteger(L, code);
lua_pushinteger(L, action);
lua_pushinteger(L, mods);
lua_call(L, 4, 0);
int err = lua_pcall(L, 4, 0, 0);
if (err != LUA_OK) {
Error();
}
#endif // LUA_SCRIPTING
}
@@ -101,6 +107,9 @@ void Lua::LuaMousePositionHandler(Window *window, double xpos, double ypos, doub
lua_pushnumber(L, ypos);
lua_pushnumber(L, relx);
lua_pushnumber(L, rely);
lua_call(L, 4, 0);
int err = lua_pcall(L, 4, 0, 1);
if (err != LUA_OK) {
Error();
}
#endif // LUA_SCRIPTING
}

View File

@@ -21,7 +21,7 @@ public:
void Initialize();
void Update(double delta);
void Close();
void Error();
static void Error();
bool HasHook(const char *name);
private:
#ifdef LUA_SCRIPTING

View File

@@ -8,7 +8,6 @@ public:
virtual void Initialize() = 0;
virtual void Update(double delta) = 0;
virtual void Close() = 0;
virtual void Error() = 0;
virtual bool HasHook(const char * name) = 0;
static ScriptingLanguage *GetCurrentLanguage();
protected: