d42be1fcd31eeda4c09fc2f4741b86dc2cd484e9
1 /* LuaEvent - Copyright (C) 2007 Thomas Harning <harningt@gmail.com>
2 * Licensed as LGPL - See doc/COPYING for details */
6 #define WEAK_REF_LOCATION le_register_utility
8 static void get_weakref_table(lua_State
* L
) {
9 lua_pushlightuserdata(L
, WEAK_REF_LOCATION
);
10 lua_gettable(L
, LUA_REGISTRYINDEX
);
13 void le_weak_ref(lua_State
* L
, void* ptr
, int idx
) {
15 lua_pushlightuserdata(L
, ptr
);
17 lua_pushvalue(L
, idx
);
20 void le_weak_unref(lua_State
* L
, void* ptr
) {
22 lua_pushlightuserdata(L
, ptr
);
27 void le_weak_get(lua_State
* L
, void* ptr
) {
29 lua_pushlightuserdata(L
, ptr
);
33 static void push_weak_table(lua_State
* L
, const char* mode
) {
35 lua_createtable(L
,0,1);
36 lua_pushstring(L
,mode
);
37 lua_setfield(L
,-2,"__mode");
38 lua_setmetatable(L
,-2);
41 void le_register_utility(lua_State
* L
) {
42 lua_pushlightuserdata(L
, WEAK_REF_LOCATION
);
43 push_weak_table(L
, "v");
44 lua_settable(L
, LUA_REGISTRYINDEX
);