On Thu, 5 Sep 2013 08:45:33 +0200 Natanael Copa <nc...@alpinelinux.org> wrote:
> Adjust code for Lua 5.2 and keep compatibility with Lua 5.1. > > We also fix a bug in the parsing of /proc/mounts while here. After some discussion on IRC, we decided the bug fix should be split out. There is also one more change needed below... > Signed-off-by: Natanael Copa <nc...@alpinelinux.org> > --- > src/lua-lxc/core.c | 10 ++++++++-- > src/lua-lxc/lxc.lua | 18 ++++++++++++++---- > 2 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c > index 9ccbab4..d404707 100644 > --- a/src/lua-lxc/core.c > +++ b/src/lua-lxc/core.c > @@ -25,9 +25,15 @@ > #define _GNU_SOURCE > #include <lua.h> > #include <lauxlib.h> > +#include <assert.h> > #include <string.h> > #include <lxc/lxccontainer.h> > > +#if LUA_VERSION_NUM < 502 > +#define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l)) > +#define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l)) > +#endif > + > #ifdef NO_CHECK_UDATA > #define checkudata(L,i,tname) lua_touserdata(L, i) > #else > @@ -389,7 +395,7 @@ static int lxc_lib_uninit(lua_State *L) { > LUALIB_API int luaopen_lxc_core(lua_State *L) { > /* this is where we would initialize liblxc.so if we needed to */ > > - luaL_register(L, "lxc", lxc_lib_methods); > + luaL_newlib(L, lxc_lib_methods); > > lua_newuserdata(L, 0); > lua_newtable(L); /* metatable */ > @@ -401,12 +407,12 @@ LUALIB_API int luaopen_lxc_core(lua_State *L) { > lua_rawset(L, -3); > > luaL_newmetatable(L, CONTAINER_TYPENAME); > + luaL_setfuncs(L, lxc_container_methods, 0); > lua_pushvalue(L, -1); /* push metatable */ > lua_pushstring(L, "__gc"); > lua_pushcfunction(L, container_gc); > lua_settable(L, -3); > lua_setfield(L, -2, "__index"); /* metatable.__index = > metatable */ > - luaL_register(L, NULL, lxc_container_methods); > lua_pop(L, 1); > return 1; > } > diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua > index b48eb76..4ef1ff9 100755 > --- a/src/lua-lxc/lxc.lua > +++ b/src/lua-lxc/lxc.lua > @@ -32,6 +32,11 @@ local lxc_path > local cgroup_path > local log_level = 3 > > +-- lua 5.1 compat > +if table.unpack == nil then > + table.unpack = unpack > +end > + > -- the following two functions can be useful for debugging > function printf(...) > local function wrapper(...) io.write(string.format(...)) end > @@ -89,6 +94,9 @@ function cgroup_path_get() > while true do > local c > line = f:read() > + if line == nil then > + break > + end > c = line:split(" ", 6) > if (c[1] == "cgroup") then > cgroup_path = dirname(c[2]) > @@ -283,7 +291,7 @@ function container:stat_get_ints(controller, > item, coords) table.insert(result, val) > end > end > - return unpack(result) > + return table.unpack(result) > end > > -- read an integer from a cgroup file > @@ -356,10 +364,10 @@ function container:stats_get(total) > return stat > end > > - > +local M = { container = container } stats_clear needs to be moved here and made: function M.stats_clear(stat) so that it can be found. > -- return configured containers found in LXC_PATH directory > -function containers_configured(names_only) > +function M.containers_configured(names_only) > local containers = {} > > for dir in lfs.dir(lxc_path) do > @@ -387,7 +395,7 @@ function containers_configured(names_only) > end > > -- return running containers found in cgroup fs > -function containers_running(names_only) > +function M.containers_running(names_only) > local containers = {} > local attr > > @@ -423,3 +431,5 @@ end > > lxc_path = core.default_config_path_get() > cgroup_path = cgroup_path_get() > + > +return M ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel