From afd4a17e139ad352e32c82a87ebd06175f2aa6a5 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Tue, 3 Feb 2015 23:03:49 +0000 Subject: Add fake __gc and support newer library registration --- lib/supple/capi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/supple/capi.c b/lib/supple/capi.c index 34e6169..e12521d 100644 --- a/lib/supple/capi.c +++ b/lib/supple/capi.c @@ -105,6 +105,13 @@ supple_capi_proxy_type(lua_State *L) return 1; } +static int +supple_capi_fake_gc(lua_State *L) +{ + (void)L; + return 0; +} + static int supple_capi_new_proxy(lua_State *L) { @@ -128,6 +135,9 @@ supple_capi_new_proxy(lua_State *L) lua_pushvalue(L, 1); lua_pushcclosure(L, supple_capi_proxy_type, 1); lua_setfield(L, -2, "__type"); + /* put a dummy __gc so that the fasttm stuff doesn't bite us later */ + lua_pushcclosure(L, supple_capi_fake_gc, 0); + lua_setfield(L, -2, "__gc"); /* And now prevent anything poking in us later */ lua_pushboolean(L, 1); lua_setfield(L, -2, "__metatable"); @@ -438,7 +448,11 @@ supple_capi_functions[] = { int luaopen_supple_capi(lua_State *L) { +#if (LUA_VERSION_NUM > 501) + luaL_newlib(L, supple_capi_functions); +#else luaL_register(L, "supple.capi", supple_capi_functions); +#endif lua_pushnumber(L, CAPI_API); lua_setfield(L, -2, "_API"); lua_pushnumber(L, CAPI_ABI); -- cgit v1.2.1