diff --git a/c/c_hook.c b/c/c_hook.c index 181db43..64e1229 100644 --- a/c/c_hook.c +++ b/c/c_hook.c @@ -24,6 +24,22 @@ typedef clock_t hook_time_t; #define CLOCK_FUNCTION clock #endif +#if !defined(luaL_newlibtable) \ + && (!defined LUA_VERSION_NUM || LUA_VERSION_NUM==501) +static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { + luaL_checkstack(L, nup+1, "too many upvalues"); + for (; l->name != NULL; l++) { /* fill the table with given functions */ + int i; + lua_pushstring(L, l->name); + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -(nup+1)); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + lua_settable(L, -(nup + 3)); + } + lua_pop(L, nup); /* remove upvalues */ +} +#endif + /*============================================================================*/ @@ -168,7 +184,8 @@ static luaL_Reg hook_functions[] = LUALIB_API int luaopen_luatrace_c_hook(lua_State *L) { /* Register the module functions */ - luaL_register(L, "c_hook", hook_functions); + lua_newtable(L); + luaL_setfuncs(L,hook_functions,0); return 1; }