# HG changeset patch # User jbe # Date 1471722962 -7200 # Node ID 73d832c4a9b51801d1508cdd2088f7baabf4c8ce # Parent 5f2a2f73e9d372e01ce2b2069669df26219fbdf1 Use luaL_setmetatable instead of luaL_getmetatable and lua_setmetatable diff -r 5f2a2f73e9d3 -r 73d832c4a9b5 moonbridge_io.c --- a/moonbridge_io.c Tue Jul 26 16:22:21 2016 +0200 +++ b/moonbridge_io.c Sat Aug 20 21:56:02 2016 +0200 @@ -782,8 +782,7 @@ handle->fd = *fd; /* required for set_linger call */ moonbr_io_handle_set_linger(L, handle, 0); handle->fd = -1; /* avoid closing incomplete handle */ - luaL_getmetatable(L, MOONBR_IO_HANDLE_MT_REGKEY); - lua_setmetatable(L, -2); + luaL_setmetatable(L, MOONBR_IO_HANDLE_MT_REGKEY); lua_newtable(L); // uservalue lua_newtable(L); lua_setfield(L, -2, "writequeue"); @@ -867,8 +866,7 @@ lua_pushinteger(L, ntohs(addr_in.sin_port)); lua_setfield(L, -2, "remote_tcpport"); } - luaL_getmetatable(L, MOONBR_IO_HANDLE_PUBLIC_MT_REGKEY); - lua_setmetatable(L, -2); + luaL_setmetatable(L, MOONBR_IO_HANDLE_PUBLIC_MT_REGKEY); lua_setfield(L, -2, "public"); lua_setuservalue(L, -2); handle->fd = *fd; @@ -1278,8 +1276,7 @@ child->pid = 0; lua_newtable(L); lua_setuservalue(L, -2); - luaL_getmetatable(L, MOONBR_IO_CHILD_MT_REGKEY); - lua_setmetatable(L, -2); + luaL_setmetatable(L, MOONBR_IO_CHILD_MT_REGKEY); if (socketpair(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, sockin)) { moonbr_io_errmsg(); lua_pushnil(L);