| 157 | } |
| 158 | |
| 159 | static void set_methods(lua_State *L, |
| 160 | const char *metatablename, |
| 161 | const struct luaL_Reg *methods) { |
| 162 | luaL_getmetatable(L, metatablename); // mt |
| 163 | // Create the __index table |
| 164 | lua_pushstring(L, "__index"); // mt, "__index" |
| 165 | lua_newtable(L); // mt, "__index", t |
| 166 | for (; methods->name; methods++) { |
| 167 | lua_pushstring(L, methods->name); // mt, "__index", t, "name" |
| 168 | lua_pushcfunction(L, methods->func); // mt, "__index", t, "name", func |
| 169 | lua_rawset(L, -3); // mt, "__index", t |
| 170 | } |
| 171 | lua_rawset(L, -3); // mt |
| 172 | lua_pop(L, 1); |
| 173 | } |
| 174 | |
| 175 | int luaopen_libluasocket(lua_State *L) { |
| 176 | luaL_newmetatable(L, SOCKET_GENERIC); |
no outgoing calls
no test coverage detected