mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-21 10:15:23 +12:00
[Lua] Add event handles
This commit is contained in:
parent
baa9cab051
commit
7936a87fb0
3 changed files with 73 additions and 9 deletions
include
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue