From 5a9bbd481f94119488d845f5b8272734dfda82cc Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 17 Mar 2019 11:41:14 +0800 Subject: *enum --- Source/3rdParty/Luax/luax_enum.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'Source/3rdParty/Luax/luax_enum.cpp') diff --git a/Source/3rdParty/Luax/luax_enum.cpp b/Source/3rdParty/Luax/luax_enum.cpp index a58593a..af832d1 100644 --- a/Source/3rdParty/Luax/luax_enum.cpp +++ b/Source/3rdParty/Luax/luax_enum.cpp @@ -34,4 +34,34 @@ namespace Luax return luaL_error(L, "Enum called \"%s\" is readonly.", name); } + //-------------------------------------------------------------------------------------------------------------- + + int LuaxPlainEnum::registry(lua_State* L) + { + // params: + // 1: enum name + // 2: metatable + + cc8* name = luaL_checkstring(L, 1); + + if (!lua_istable(L, 2)) + { + return luaL_error(L, "Create plain enum failed. Require table, but get %s", luaL_typename(L, 2)); + } + + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + + lua_pushstring(L, name); + lua_pushcclosure(L, l_rmt__newindex, 1); + lua_setfield(L, -2, "__newindex"); + + lua_newtable(L); // enum table + + lua_pushvalue(L, -2); // metatable + lua_setmetatable(L, -2); + + return 1; + } + } \ No newline at end of file -- cgit v1.1-26-g67d0