--- ubus/lua/ubus.c.orig 2016-05-24 20:00:49.000000000 +0300 +++ ubus/lua/ubus.c 2016-06-16 17:22:31.986092619 +0300 @@ -293,7 +293,7 @@ ubus_method_handler(struct ubus_context lua_remove(state, -2); lua_remove(state, -2); - if (lua_isfunction(state, -1)) { + if (lua_isfunction(state, -1) || lua_istable(state, -1)) { lua_pushlightuserdata(state, req); if (!msg) lua_pushnil(state); @@ -359,13 +359,29 @@ static int ubus_lua_load_methods(lua_Sta lua_gettable(L, -3); /* check if the method table is valid */ - if ((lua_type(L, -2) != LUA_TFUNCTION) || + if (((lua_type(L, -2) != LUA_TFUNCTION) && (lua_type(L, -2) != LUA_TTABLE)) || (lua_type(L, -1) != LUA_TTABLE) || lua_objlen(L, -1)) { lua_pop(L, 2); return 1; } + if (lua_type(L, -2) == LUA_TTABLE) { + /* check for metatable */ + if (lua_getmetatable(L, -2) == 0) { + lua_pop(L, 2); + return 1; + } + lua_pushstring(L, "__call"); + lua_rawget(L, -2); + lua_replace(L, -2); + if (lua_isnil(L, -1)) { + lua_pop(L, 6); + return 1; + } + lua_pop(L, 1); + } + /* store function pointer */ lua_pushvalue(L, -2); lua_setfield(L, -6, lua_tostring(L, -5));