aboutsummaryrefslogtreecommitdiff
path: root/src/LuaRuntime.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-04-20 19:20:33 +0530
committerAkshay Nair <phenax5@gmail.com>2025-05-02 16:15:59 +0530
commit2f1e73741da625c173156102457d5442b27cd953 (patch)
treef59bd3f896fd5473d71a3fdaf7fa4833add248b5 /src/LuaRuntime.cpp
parent31872258b18e81d5f973080e5130ebf49db3271f (diff)
downloadnull-browser-2f1e73741da625c173156102457d5442b27cd953.tar.gz
null-browser-2f1e73741da625c173156102457d5442b27cd953.zip
Add configuration directory loading + --config-dir cli arg
Diffstat (limited to 'src/LuaRuntime.cpp')
-rw-r--r--src/LuaRuntime.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp
index cb5a69a..b4c39a2 100644
--- a/src/LuaRuntime.cpp
+++ b/src/LuaRuntime.cpp
@@ -15,7 +15,7 @@ LuaRuntime::LuaRuntime() {
state = luaL_newstate();
luaL_openlibs(state);
- init_lua_package_path();
+ init_builtins_package_path();
init_web_api();
}
@@ -57,16 +57,9 @@ void LuaRuntime::init_web_api() {
});
}
-void LuaRuntime::init_lua_package_path() {
- 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");
- });
+void LuaRuntime::init_builtins_package_path() {
+ auto builtins_lua_path = QString(PROJECT_LUA_PATH);
+ append_package_path(builtins_lua_path);
}
void LuaRuntime::evaluate(const QString &code) {
@@ -84,6 +77,17 @@ void LuaRuntime::evaluate(const QString &code) {
});
}
+void LuaRuntime::append_package_path(const QString &path) {
+ preserve_top(state, {
+ lua_getglobal(state, "package");
+ lua_getfield(state, -1, "path");
+ auto pkg_path = QString(lua_tostring(state, -1)) + ";" + path;
+ lua_pop(state, 1);
+ lua_pushstring(state, pkg_path.toStdString().c_str());
+ lua_setfield(state, -2, "path");
+ });
+}
+
void LuaRuntime::load_file_sync(const QString &path) {
preserve_top(state, {
if (luaL_dofile(state, path.toStdString().c_str()) != LUA_OK) {