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
+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) {