diff --git a/include/luak/luak.h b/include/luak/luak.h index 3a59ac5..0ca4fab 100644 --- a/include/luak/luak.h +++ b/include/luak/luak.h @@ -21,6 +21,7 @@ struct kiwmi_lua { }; int luaK_callback_register_dispatch(lua_State *L); +int luaK_usertype_ref_equal(lua_State *L); struct kiwmi_lua *luaK_create(struct kiwmi_server *server); bool luaK_dofile(struct kiwmi_lua *lua, const char *config_path); void luaK_destroy(struct kiwmi_lua *lua); diff --git a/kiwmi/luak/kiwmi_cursor.c b/kiwmi/luak/kiwmi_cursor.c index 9aaa788..8d30455 100644 --- a/kiwmi/luak/kiwmi_cursor.c +++ b/kiwmi/luak/kiwmi_cursor.c @@ -231,5 +231,8 @@ luaK_kiwmi_cursor_register(lua_State *L) luaL_newlib(L, kiwmi_cursor_events); lua_setfield(L, -2, "__events"); + lua_pushcfunction(L, luaK_usertype_ref_equal); + lua_setfield(L, -2, "__eq"); + return 0; } diff --git a/kiwmi/luak/kiwmi_keyboard.c b/kiwmi/luak/kiwmi_keyboard.c index fbfd77a..3e56bad 100644 --- a/kiwmi/luak/kiwmi_keyboard.c +++ b/kiwmi/luak/kiwmi_keyboard.c @@ -191,5 +191,8 @@ luaK_kiwmi_keyboard_register(lua_State *L) luaL_newlib(L, kiwmi_keyboard_events); lua_setfield(L, -2, "__events"); + lua_pushcfunction(L, luaK_usertype_ref_equal); + lua_setfield(L, -2, "__eq"); + return 0; } diff --git a/kiwmi/luak/kiwmi_lua_callback.c b/kiwmi/luak/kiwmi_lua_callback.c index b1f5dd6..0202d12 100644 --- a/kiwmi/luak/kiwmi_lua_callback.c +++ b/kiwmi/luak/kiwmi_lua_callback.c @@ -76,6 +76,9 @@ luaK_kiwmi_lua_callback_register(lua_State *L) lua_setfield(L, -2, "__index"); luaL_setfuncs(L, kiwmi_lua_callback_methods, 0); + lua_pushcfunction(L, luaK_usertype_ref_equal); + lua_setfield(L, -2, "__eq"); + return 0; } diff --git a/kiwmi/luak/kiwmi_output.c b/kiwmi/luak/kiwmi_output.c index dbd8005..5347335 100644 --- a/kiwmi/luak/kiwmi_output.c +++ b/kiwmi/luak/kiwmi_output.c @@ -179,5 +179,8 @@ luaK_kiwmi_output_register(lua_State *L) luaL_newlib(L, kiwmi_output_events); lua_setfield(L, -2, "__events"); + lua_pushcfunction(L, luaK_usertype_ref_equal); + lua_setfield(L, -2, "__eq"); + return 0; } diff --git a/kiwmi/luak/kiwmi_server.c b/kiwmi/luak/kiwmi_server.c index d953140..f27f4ae 100644 --- a/kiwmi/luak/kiwmi_server.c +++ b/kiwmi/luak/kiwmi_server.c @@ -273,5 +273,8 @@ luaK_kiwmi_server_register(lua_State *L) luaL_newlib(L, kiwmi_server_events); lua_setfield(L, -2, "__events"); + lua_pushcfunction(L, luaK_usertype_ref_equal); + lua_setfield(L, -2, "__eq"); + return 0; } diff --git a/kiwmi/luak/kiwmi_view.c b/kiwmi/luak/kiwmi_view.c index 077fc82..4879ad1 100644 --- a/kiwmi/luak/kiwmi_view.c +++ b/kiwmi/luak/kiwmi_view.c @@ -267,5 +267,8 @@ luaK_kiwmi_view_register(lua_State *L) luaL_newlib(L, kiwmi_view_events); lua_setfield(L, -2, "__events"); + lua_pushcfunction(L, luaK_usertype_ref_equal); + lua_setfield(L, -2, "__eq"); + return 0; } diff --git a/kiwmi/luak/luak.c b/kiwmi/luak/luak.c index 3552728..2f94fb7 100644 --- a/kiwmi/luak/luak.c +++ b/kiwmi/luak/luak.c @@ -47,6 +47,20 @@ luaK_callback_register_dispatch(lua_State *L) return 1; } +int +luaK_usertype_ref_equal(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TUSERDATA); + luaL_checktype(L, 2, LUA_TUSERDATA); + + void *a = *(void **)lua_touserdata(L, 1); + void *b = *(void **)lua_touserdata(L, 2); + + lua_pushboolean(L, a == b); + + return 1; +} + struct kiwmi_lua * luaK_create(struct kiwmi_server *server) {