| 1022 | }; |
| 1023 | |
| 1024 | int |
| 1025 | l_selection_register(lua_State *L) |
| 1026 | { |
| 1027 | /* Table of instance methods and static methods. */ |
| 1028 | luaL_newlib(L, l_selection_methods); |
| 1029 | |
| 1030 | /* metatable = { __name = "selection", __gc = l_selection_gc } */ |
| 1031 | luaL_newmetatable(L, "selection"); |
| 1032 | luaL_setfuncs(L, l_selection_meta, 0); |
| 1033 | |
| 1034 | /* metatable.__index points at the selection method table. */ |
| 1035 | lua_pushvalue(L, -2); |
| 1036 | lua_setfield(L, -2, "__index"); |
| 1037 | |
| 1038 | /* Don't let lua code mess with the real metatable. |
| 1039 | Instead offer a fake one that only contains __gc. */ |
| 1040 | luaL_newlib(L, l_selection_meta); |
| 1041 | lua_setfield(L, -2, "__metatable"); |
| 1042 | |
| 1043 | /* We don't need the metatable anymore. It's safe in the |
| 1044 | Lua registry for use by luaL_setmetatable. */ |
| 1045 | lua_pop(L, 1); |
| 1046 | |
| 1047 | /* global selection = the method table we created at the start */ |
| 1048 | lua_setglobal(L, "selection"); |
| 1049 | |
| 1050 | return 0; |
| 1051 | } |