Skip to content

Commit

Permalink
always hold for globally loaded libraries
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Jun 27, 2024
1 parent 2da738e commit ed1cea4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static const char *carray_registry;
static const char *cfunc_registry;
static const char *ctype_registry;
static const char *ctdef_registry;
static const char *clib_registry;

#if LUA_VERSION_NUM < 503

Expand Down Expand Up @@ -2038,6 +2039,13 @@ static int load_lib(lua_State *L, const char *path, bool global)
luaL_getmetatable(L, CLIB_MT);
lua_setmetatable(L, -2);

if (global) {
lua_rawgetp(L, LUA_REGISTRYINDEX, &clib_registry);
lua_pushvalue(L, -2);
lua_rawsetp(L, -2, lib);
lua_pop(L, 1);
}

return 1;
}

Expand Down Expand Up @@ -2396,6 +2404,9 @@ int luaopen_ffi(lua_State *L)
lua_newtable(L);
lua_rawsetp(L, LUA_REGISTRYINDEX, &ctdef_registry);

lua_newtable(L);
lua_rawsetp(L, LUA_REGISTRYINDEX, &clib_registry);

createmetatable(L, CDATA_MT, cdata_methods);
createmetatable(L, CTYPE_MT, ctype_methods);
createmetatable(L, CLIB_MT, clib_methods);
Expand Down

0 comments on commit ed1cea4

Please sign in to comment.