[Lua] Add event handles

This commit is contained in:
wheremyfoodat 2023-09-18 00:35:29 +03:00
parent baa9cab051
commit 7936a87fb0
3 changed files with 73 additions and 9 deletions
include

View file

@ -2,6 +2,13 @@
#include "helpers.hpp"
#include "memory.hpp"
// The kinds of events that can cause a Lua call.
// Frame: Call program on frame end
// TODO: Add more
enum class LuaEvent {
Frame,
};
#ifdef PANDA3DS_ENABLE_LUA
extern "C" {
#include <lauxlib.h>
@ -14,6 +21,9 @@ extern "C" {
class LuaManager {
lua_State* L = nullptr;
bool initialized = false;
bool haveScript = false;
void signalEventInternal(LuaEvent e);
public:
// For Lua we must have some global pointers to our emulator objects to use them in script code via thunks. See the thunks in lua.cpp as an
@ -27,6 +37,11 @@ class LuaManager {
void initializeThunks();
void loadFile(const char* path);
void reset();
void signalEvent(LuaEvent e) {
if (haveScript) [[unlikely]] {
signalEventInternal(e);
}
}
};
#elif // Lua not enabled, Lua manager does nothing
@ -38,5 +53,6 @@ class LuaManager {
void initialize() {}
void loadFile(const char* path) {}
void reset() {}
void signalEvent(LuaEvent e) {}
};
#endif