Set Lua cpath along with path

This commit is contained in:
Henri DF 2016-03-04 17:53:39 -08:00
parent cc4837312e
commit 8c6bb8a236
4 changed files with 35 additions and 24 deletions

View File

@ -33,8 +33,6 @@ $ make
as a result, you should have a digwatch executable `build/userspace/digwatch/digwatch`.
Still not quite done yet! we need to install the [lpeg](http://www.inf.puc-rio.br/~roberto/lpeg/) Lua library. (This should be done automatically as part of the build of course...). To install it, just do: `luarocks install lpeg`.
### Running

View File

@ -125,6 +125,37 @@ void do_inspect(sinsp* inspector,
}
}
void add_lua_path(lua_State *ls, string path)
{
string cpath = string(path);
path += "?.lua";
cpath += "?.so";
lua_getglobal(ls, "package");
lua_getfield(ls, -1, "path");
string cur_path = lua_tostring(ls, -1 );
cur_path += ';';
lua_pop(ls, 1);
cur_path.append(path.c_str());
lua_pushstring(ls, cur_path.c_str());
lua_setfield(ls, -2, "path");
lua_getfield(ls, -1, "cpath");
string cur_cpath = lua_tostring(ls, -1 );
cur_cpath += ';';
lua_pop(ls, 1);
cur_cpath.append(cpath.c_str());
lua_pushstring(ls, cur_cpath.c_str());
lua_setfield(ls, -2, "cpath");
lua_pop(ls, 1);
}
//
// ARGUMENT PARSING AND PROGRAM SETUP
//
@ -241,8 +272,9 @@ int digwatch_init(int argc, char **argv)
// Initialize Lua interpreter
ls = lua_open();
luaL_openlibs(ls);
add_lua_path(ls, lua_dir);
rules = new digwatch_rules(inspector, ls, lua_main_filename, lua_dir);
rules = new digwatch_rules(inspector, ls, lua_main_filename);
digwatch_formats::init(inspector, ls);
digwatch_fields::init(inspector, ls);

View File

@ -7,33 +7,15 @@ extern "C" {
}
digwatch_rules::digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename, string lua_dir)
digwatch_rules::digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename)
{
m_ls = ls;
m_lua_parser = new lua_parser(inspector, m_ls);
add_lua_path(lua_dir);
load_compiler(lua_main_filename);
}
void digwatch_rules::add_lua_path(string path)
{
path += "?.lua";
lua_getglobal(m_ls, "package");
lua_getfield(m_ls, -1, "path");
string cur_path = lua_tostring(m_ls, -1 );
cur_path += ';';
cur_path.append(path.c_str());
lua_pop(m_ls, 1);
lua_pushstring(m_ls, cur_path.c_str());
lua_setfield(m_ls, -2, "path");
lua_pop(m_ls, 1);
}
void digwatch_rules::load_compiler(string lua_main_filename)
{

View File

@ -6,13 +6,12 @@
class digwatch_rules
{
public:
digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename, string lua_dir);
digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename);
~digwatch_rules();
void load_rules(string rules_filename);
sinsp_filter* get_filter();
private:
void add_lua_path(string path);
void load_compiler(string lua_main_filename);
lua_parser* m_lua_parser;