Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | From c2782a6ca968190e221c25b0890600ba8cd43798 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 23 Oct 2015 00:23:15 -0700 |
| 4 | Subject: [PATCH] libsinsp: Port to build with lua >= 5.2 |
| 5 | |
| 6 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 7 | --- |
| 8 | userspace/libsinsp/chisel.cpp | 40 +++++++++++++++++++++++++++++----------- |
| 9 | 1 file changed, 29 insertions(+), 11 deletions(-) |
| 10 | |
| 11 | diff --git a/userspace/libsinsp/chisel.cpp b/userspace/libsinsp/chisel.cpp |
| 12 | index 3cfbd8d..2db9348 100644 |
| 13 | --- a/userspace/libsinsp/chisel.cpp |
| 14 | +++ b/userspace/libsinsp/chisel.cpp |
| 15 | @@ -94,7 +94,7 @@ void lua_stackdump(lua_State *L) |
| 16 | // Lua callbacks |
| 17 | /////////////////////////////////////////////////////////////////////////////// |
| 18 | #ifdef HAS_LUA_CHISELS |
| 19 | -const static struct luaL_reg ll_sysdig [] = |
| 20 | +const static struct luaL_Reg ll_sysdig [] = |
| 21 | { |
| 22 | {"set_filter", &lua_cbacks::set_global_filter}, |
| 23 | {"set_snaplen", &lua_cbacks::set_snaplen}, |
| 24 | @@ -120,7 +120,7 @@ const static struct luaL_reg ll_sysdig [] = |
| 25 | {NULL,NULL} |
| 26 | }; |
| 27 | |
| 28 | -const static struct luaL_reg ll_chisel [] = |
| 29 | +const static struct luaL_Reg ll_chisel [] = |
| 30 | { |
| 31 | {"request_field", &lua_cbacks::request_field}, |
| 32 | {"set_filter", &lua_cbacks::set_filter}, |
| 33 | @@ -131,7 +131,7 @@ const static struct luaL_reg ll_chisel [] = |
| 34 | {NULL,NULL} |
| 35 | }; |
| 36 | |
| 37 | -const static struct luaL_reg ll_evt [] = |
| 38 | +const static struct luaL_Reg ll_evt [] = |
| 39 | { |
| 40 | {"field", &lua_cbacks::field}, |
| 41 | {"get_num", &lua_cbacks::get_num}, |
| 42 | @@ -853,10 +853,28 @@ bool sinsp_chisel::parse_view_info(lua_State *ls, OUT chisel_desc* cd) |
| 43 | |
| 44 | |
| 45 | #ifdef HAS_LUA_CHISELS |
| 46 | +static void chisel_lua_registerlib(lua_State *L, const char *libname, |
| 47 | + const luaL_Reg *l, int ind) |
| 48 | +{ |
| 49 | +#if LUA_VERSION_NUM >= 502 |
| 50 | + if (libname) |
| 51 | + { |
| 52 | + lua_newtable(L); |
| 53 | + luaL_setfuncs(L, l, ind); |
| 54 | + lua_pushvalue(L, -1); |
| 55 | + lua_setglobal(L, libname); |
| 56 | + } |
| 57 | + else |
| 58 | + luaL_setfuncs(L, l, ind); |
| 59 | +#else |
| 60 | + luaL_register(L, libname, l); |
| 61 | +#endif |
| 62 | +} |
| 63 | + |
| 64 | // Initializes a lua chisel |
| 65 | bool sinsp_chisel::init_lua_chisel(chisel_desc &cd, string const &fpath) |
| 66 | { |
| 67 | - lua_State* ls = lua_open(); |
| 68 | + lua_State* ls = luaL_newstate(); |
| 69 | if(ls == NULL) |
| 70 | { |
| 71 | return false; |
| 72 | @@ -867,9 +885,9 @@ bool sinsp_chisel::init_lua_chisel(chisel_desc &cd, string const &fpath) |
| 73 | // |
| 74 | // Load our own lua libs |
| 75 | // |
| 76 | - luaL_openlib(ls, "sysdig", ll_sysdig, 0); |
| 77 | - luaL_openlib(ls, "chisel", ll_chisel, 0); |
| 78 | - luaL_openlib(ls, "evt", ll_evt, 0); |
| 79 | + chisel_lua_registerlib(ls, "sysdig", ll_sysdig, 0); |
| 80 | + chisel_lua_registerlib(ls, "chisel", ll_chisel, 0); |
| 81 | + chisel_lua_registerlib(ls, "evt", ll_evt, 0); |
| 82 | |
| 83 | // |
| 84 | // Add our chisel paths to package.path |
| 85 | @@ -1111,16 +1129,16 @@ void sinsp_chisel::load(string cmdstr) |
| 86 | // |
| 87 | // Open the script |
| 88 | // |
| 89 | - m_ls = lua_open(); |
| 90 | + m_ls = luaL_newstate(); |
| 91 | |
| 92 | luaL_openlibs(m_ls); |
| 93 | |
| 94 | // |
| 95 | // Load our own lua libs |
| 96 | // |
| 97 | - luaL_openlib(m_ls, "sysdig", ll_sysdig, 0); |
| 98 | - luaL_openlib(m_ls, "chisel", ll_chisel, 0); |
| 99 | - luaL_openlib(m_ls, "evt", ll_evt, 0); |
| 100 | + chisel_lua_registerlib(m_ls, "sysdig", ll_sysdig, 0); |
| 101 | + chisel_lua_registerlib(m_ls, "chisel", ll_chisel, 0); |
| 102 | + chisel_lua_registerlib(m_ls, "evt", ll_evt, 0); |
| 103 | |
| 104 | // |
| 105 | // Add our chisel paths to package.path |
| 106 | -- |
| 107 | 2.6.2 |
| 108 | |