-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from wheremyfoodat/lua
Embed LuaJIT part 1
- Loading branch information
Showing
7 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#include "helpers.hpp" | ||
|
||
#ifdef PANDA3DS_ENABLE_LUA | ||
extern "C" { | ||
#include <lauxlib.h> | ||
#include <lua.h> | ||
#include <lualib.h> | ||
|
||
#include "luajit.h" | ||
} | ||
|
||
class LuaManager { | ||
lua_State* L = nullptr; | ||
bool initialized = false; | ||
|
||
public: | ||
void close(); | ||
void initialize(); | ||
void loadFile(const char* path); | ||
void reset(); | ||
}; | ||
|
||
#elif // Lua not enabled, Lua manager does nothing | ||
class LuaManager { | ||
public: | ||
void close() {} | ||
void initialize() {} | ||
void loadFile(const char* path) {} | ||
void reset() {} | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |