mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
Embed LuaJIT part 1
This commit is contained in:
parent
c0e3d6d7dd
commit
b908f3efc1
7 changed files with 99 additions and 2 deletions
37
src/lua.cpp
Normal file
37
src/lua.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifdef PANDA3DS_ENABLE_LUA
|
||||
#include "lua.hpp"
|
||||
|
||||
void LuaManager::initialize() {
|
||||
L = luaL_newstate(); // Open Lua
|
||||
|
||||
if (!L) {
|
||||
printf("Lua initialization failed, continuing without Lua");
|
||||
initialized = false;
|
||||
return;
|
||||
}
|
||||
|
||||
luaL_openlibs(L);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void LuaManager::close() {
|
||||
if (initialized) {
|
||||
lua_close(L);
|
||||
initialized = false;
|
||||
L = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaManager::loadFile(const char* path) {
|
||||
int status = luaL_loadfile(L, path); // load Lua script
|
||||
int ret = lua_pcall(L, 0, 0, 0); // tell Lua to run the script
|
||||
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "%s\n", lua_tostring(L, -1)); // tell us what mistake we made
|
||||
}
|
||||
}
|
||||
|
||||
void LuaManager::reset() {
|
||||
// Reset scripts
|
||||
}
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue