Add equality for Lua types

This commit is contained in:
buffet 2020-01-08 17:33:01 +00:00
parent 838aaf2daf
commit 5dc2c62d89
8 changed files with 33 additions and 0 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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)
{