summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-02-03 23:03:49 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-02-03 23:03:49 +0000
commitafd4a17e139ad352e32c82a87ebd06175f2aa6a5 (patch)
treefba0cd5b89f4d6ec12f3f050530c512ff2e14fa4
parentdb26fa29533ca55606f79892a420d6c031f60547 (diff)
downloadsupple-afd4a17e139ad352e32c82a87ebd06175f2aa6a5.tar.gz
Add fake __gc and support newer library registration
-rw-r--r--lib/supple/capi.c14
1 files changed, 14 insertions, 0 deletions
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
@@ -106,6 +106,13 @@ supple_capi_proxy_type(lua_State *L)
}
static int
+supple_capi_fake_gc(lua_State *L)
+{
+ (void)L;
+ return 0;
+}
+
+static int
supple_capi_new_proxy(lua_State *L)
{
void *proxy_ptr;
@@ -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);