fix(lua): Make rtorrent.lua accessible at start

This commit is contained in:
PRESFIL
2025-06-11 18:34:26 +00:00
committed by Jari Sundell
parent d9976af767
commit f8ec1ca95e
5 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -196,4 +196,4 @@ libsub_root_a_SOURCES = \
thread_worker.h
AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir)
AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -DPACKAGE_DATADIR=\"$(pkgdatadir)\"
+14
View File
@@ -25,6 +25,7 @@ namespace rpc {
const int LuaEngine::flag_string;
const std::string LuaEngine::module_name = "rtorrent";
const std::string LuaEngine::local_path = PACKAGE_DATADIR "/lua/?.lua;" PACKAGE_DATADIR "/lua/?/init.lua";
#ifdef HAVE_LUA
@@ -32,6 +33,7 @@ LuaEngine::LuaEngine() {
m_luaState = luaL_newstate();
luaL_openlibs(m_luaState);
set_package_preload();
override_package_path();
}
LuaEngine::~LuaEngine() { lua_close(m_luaState); }
@@ -46,6 +48,18 @@ LuaEngine::set_package_preload() {
lua_pop(l_state, 2);
}
void
LuaEngine::override_package_path() {
auto l_state = m_luaState;
lua_getglobal(l_state, "package");
lua_getfield(l_state, -1, "path");
std::string current_path(lua_tostring(l_state, -1));
std::string new_path = local_path + ';' + current_path;
lua_pushstring(l_state, new_path.c_str());
lua_setfield(l_state, -3, "path");
lua_pop(l_state, 2);
}
void
check_lua_status(lua_State* l_state, int status) {
if (status != LUA_OK) {
+2
View File
@@ -14,6 +14,7 @@ class LuaEngine {
public:
static const int flag_string = 0x1;
static const std::string module_name;
static const std::string local_path;
LuaEngine();
~LuaEngine();
@@ -23,6 +24,7 @@ public:
static int lua_init_module(lua_State* l_state);
static int lua_rtorrent_call(lua_State* l_state);
void set_package_preload();
void override_package_path();
lua_State* state() { return m_luaState; }
private: