mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-06 10:12:30 +00:00
fix(lua): Make rtorrent.lua accessible at start
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user