summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio/src/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/nixio/src/socket.c')
-rw-r--r--libs/nixio/src/socket.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/libs/nixio/src/socket.c b/libs/nixio/src/socket.c
index f8fa3e649..258cdeece 100644
--- a/libs/nixio/src/socket.c
+++ b/libs/nixio/src/socket.c
@@ -34,6 +34,9 @@ static int nixio_socket(lua_State *L) {
const char *proto = lua_tolstring(L, 3, NULL);
nixio_sock *sock = lua_newuserdata(L, sizeof(nixio_sock));
+ if (!sock) {
+ return luaL_error(L, "out of memory");
+ }
if (!strcmp(domain, "inet")) {
sock->domain = AF_INET;
@@ -142,17 +145,12 @@ static const luaL_reg R[] = {
static const luaL_reg M[] = {
{"close", nixio_sock_close},
{"shutdown", nixio_sock_shutdown},
+ {"__gc", nixio_sock__gc},
+ {"__tostring", nixio_sock__tostring},
{NULL, NULL}
};
void nixio_open_socket(lua_State *L) {
- luaL_getmetatable(L, NIXIO_META);
- lua_pushcfunction(L, nixio_sock__gc);
- lua_setfield(L, -2, "__gc");
- lua_pushcfunction(L, nixio_sock__tostring);
- lua_setfield(L, -2, "__tostring");
- lua_pop(L, 1);
-
luaL_register(L, NULL, R);
lua_pushvalue(L, -2);