aboutsummaryrefslogtreecommitdiff
path: root/src/LuaRuntime.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-04-05 11:49:48 +0530
committerAkshay Nair <phenax5@gmail.com>2025-04-05 13:10:39 +0530
commit2e051fcc4efcfe6af2d3ef22d6a4ba63c9f1c65d (patch)
treebbea54f175105a4167f1d07ca50a4a10632b38a2 /src/LuaRuntime.cpp
parent7e09b35b008f58809ac56184a4f83ab875c038e0 (diff)
downloadnull-browser-2e051fcc4efcfe6af2d3ef22d6a4ba63c9f1c65d.tar.gz
null-browser-2e051fcc4efcfe6af2d3ef22d6a4ba63c9f1c65d.zip
Add package path to lua (only current build dir)
Diffstat (limited to 'src/LuaRuntime.cpp')
-rw-r--r--src/LuaRuntime.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index 1dc9a85..d9bc86e 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -1,6 +1,6 @@
-#include "WindowActionRouter.hpp"
-#include "lua.h"
#include <QtCore>
+#include <cstdlib>
+#include <cstring>
#include <lua.hpp>
extern "C" {
#include <luv/luv.h>
@@ -8,12 +8,29 @@ extern "C" {
#include "AsyncEventLoop.hpp"
#include "LuaRuntime.hpp"
+#include "WindowActionRouter.hpp"
LuaRuntime::LuaRuntime() {
state = luaL_newstate();
luaL_openlibs(state);
- preserve_top(state, { init_web_lib(); })
+ preserve_top(state, { init_web_lib(); });
+
+ auto lua_path = QString(PROJECT_LUA_PATH);
+ preserve_top(state, {
+ lua_getglobal(state, "package");
+ lua_getfield(state, -1, "path");
+ auto pkg_path = QString(lua_tostring(state, -1)) + ";" + lua_path;
+ lua_pop(state, 1);
+ lua_pushstring(state, pkg_path.toStdString().c_str());
+ lua_setfield(state, -2, "path");
+
+ lua_getglobal(state, "require");
+ lua_pushstring(state, "null-browser.api");
+ if (lua_pcall(state, 1, 0, 0) != LUA_OK) {
+ qCritical() << "Unable to load browser api" << lua_tostring(state, -1);
+ }
+ });
}
void LuaRuntime::start_event_loop() {