mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-16 23:22:31 +00:00
fix(lua): Make rtorrent.lua accessible at start
This commit is contained in:
+3
-1
@@ -3,8 +3,10 @@ SUBDIRS = \
|
|||||||
src \
|
src \
|
||||||
test
|
test
|
||||||
|
|
||||||
|
nobase_dist_pkgdata_DATA = \
|
||||||
|
lua/rtorrent.lua
|
||||||
|
|
||||||
EXTRA_DIST= \
|
EXTRA_DIST= \
|
||||||
rtorrent.lua \
|
|
||||||
rak/address_info.h \
|
rak/address_info.h \
|
||||||
rak/algorithm.h \
|
rak/algorithm.h \
|
||||||
rak/error_number.h \
|
rak/error_number.h \
|
||||||
|
|||||||
+1
-1
@@ -196,4 +196,4 @@ libsub_root_a_SOURCES = \
|
|||||||
thread_worker.h
|
thread_worker.h
|
||||||
|
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir)
|
AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -DPACKAGE_DATADIR=\"$(pkgdatadir)\"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace rpc {
|
|||||||
|
|
||||||
const int LuaEngine::flag_string;
|
const int LuaEngine::flag_string;
|
||||||
const std::string LuaEngine::module_name = "rtorrent";
|
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
|
#ifdef HAVE_LUA
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ LuaEngine::LuaEngine() {
|
|||||||
m_luaState = luaL_newstate();
|
m_luaState = luaL_newstate();
|
||||||
luaL_openlibs(m_luaState);
|
luaL_openlibs(m_luaState);
|
||||||
set_package_preload();
|
set_package_preload();
|
||||||
|
override_package_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaEngine::~LuaEngine() { lua_close(m_luaState); }
|
LuaEngine::~LuaEngine() { lua_close(m_luaState); }
|
||||||
@@ -46,6 +48,18 @@ LuaEngine::set_package_preload() {
|
|||||||
lua_pop(l_state, 2);
|
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
|
void
|
||||||
check_lua_status(lua_State* l_state, int status) {
|
check_lua_status(lua_State* l_state, int status) {
|
||||||
if (status != LUA_OK) {
|
if (status != LUA_OK) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class LuaEngine {
|
|||||||
public:
|
public:
|
||||||
static const int flag_string = 0x1;
|
static const int flag_string = 0x1;
|
||||||
static const std::string module_name;
|
static const std::string module_name;
|
||||||
|
static const std::string local_path;
|
||||||
|
|
||||||
LuaEngine();
|
LuaEngine();
|
||||||
~LuaEngine();
|
~LuaEngine();
|
||||||
@@ -23,6 +24,7 @@ public:
|
|||||||
static int lua_init_module(lua_State* l_state);
|
static int lua_init_module(lua_State* l_state);
|
||||||
static int lua_rtorrent_call(lua_State* l_state);
|
static int lua_rtorrent_call(lua_State* l_state);
|
||||||
void set_package_preload();
|
void set_package_preload();
|
||||||
|
void override_package_path();
|
||||||
lua_State* state() { return m_luaState; }
|
lua_State* state() { return m_luaState; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user