|
68 | 68 |
|
69 | 69 |
|
70 | 70 | static char ngx_http_lua_socket_udp_metatable_key; |
| 71 | +static char ngx_http_lua_udp_udata_metatable_key; |
71 | 72 | static u_char ngx_http_lua_socket_udp_buffer[UDP_MAX_DATAGRAM_SIZE]; |
72 | 73 |
|
73 | 74 |
|
@@ -103,6 +104,14 @@ ngx_http_lua_inject_socket_udp_api(ngx_log_t *log, lua_State *L) |
103 | 104 | lua_rawset(L, LUA_REGISTRYINDEX); |
104 | 105 | /* }}} */ |
105 | 106 |
|
| 107 | + /* udp socket object metatable */ |
| 108 | + lua_pushlightuserdata(L, &ngx_http_lua_udp_udata_metatable_key); |
| 109 | + lua_createtable(L, 0 /* narr */, 1 /* nrec */); /* metatable */ |
| 110 | + lua_pushcfunction(L, ngx_http_lua_socket_udp_upstream_destroy); |
| 111 | + lua_setfield(L, -2, "__gc"); |
| 112 | + lua_rawset(L, LUA_REGISTRYINDEX); |
| 113 | + /* }}} */ |
| 114 | + |
106 | 115 | lua_pop(L, 1); |
107 | 116 | } |
108 | 117 |
|
@@ -252,9 +261,8 @@ ngx_http_lua_socket_udp_setpeername(lua_State *L) |
252 | 261 | } |
253 | 262 |
|
254 | 263 | #if 1 |
255 | | - lua_createtable(L, 0 /* narr */, 1 /* nrec */); /* metatable */ |
256 | | - lua_pushcfunction(L, ngx_http_lua_socket_udp_upstream_destroy); |
257 | | - lua_setfield(L, -2, "__gc"); |
| 264 | + lua_pushlightuserdata(L, &ngx_http_lua_udp_udata_metatable_key); |
| 265 | + lua_rawget(L, LUA_REGISTRYINDEX); |
258 | 266 | lua_setmetatable(L, -2); |
259 | 267 | #endif |
260 | 268 |
|
|
0 commit comments