@@ -173,6 +173,10 @@ enum {
173
173
static char ngx_http_lua_req_socket_metatable_key ;
174
174
static char ngx_http_lua_raw_req_socket_metatable_key ;
175
175
static char ngx_http_lua_tcp_socket_metatable_key ;
176
+ static char ngx_http_lua_upstream_udata_metatable_key ;
177
+ static char ngx_http_lua_downstream_udata_metatable_key ;
178
+ static char ngx_http_lua_pool_udata_metatable_key ;
179
+ static char ngx_http_lua_pattern_udata_metatable_key ;
176
180
177
181
178
182
void
@@ -280,6 +284,38 @@ ngx_http_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
280
284
lua_setfield (L , -2 , "__index" );
281
285
lua_rawset (L , LUA_REGISTRYINDEX );
282
286
/* }}} */
287
+
288
+ /* {{{upstream userdata metatable */
289
+ lua_pushlightuserdata (L , & ngx_http_lua_upstream_udata_metatable_key );
290
+ lua_createtable (L , 0 /* narr */ , 1 /* nrec */ ); /* metatable */
291
+ lua_pushcfunction (L , ngx_http_lua_socket_tcp_upstream_destroy );
292
+ lua_setfield (L , -2 , "__gc" );
293
+ lua_rawset (L , LUA_REGISTRYINDEX );
294
+ /* }}} */
295
+
296
+ /* {{{downstream userdata metatable */
297
+ lua_pushlightuserdata (L , & ngx_http_lua_downstream_udata_metatable_key );
298
+ lua_createtable (L , 0 /* narr */ , 1 /* nrec */ ); /* metatable */
299
+ lua_pushcfunction (L , ngx_http_lua_socket_downstream_destroy );
300
+ lua_setfield (L , -2 , "__gc" );
301
+ lua_rawset (L , LUA_REGISTRYINDEX );
302
+ /* }}} */
303
+
304
+ /* {{{socket pool userdata metatable */
305
+ lua_pushlightuserdata (L , & ngx_http_lua_pool_udata_metatable_key );
306
+ lua_createtable (L , 0 , 1 ); /* metatable */
307
+ lua_pushcfunction (L , ngx_http_lua_socket_shutdown_pool );
308
+ lua_setfield (L , -2 , "__gc" );
309
+ lua_rawset (L , LUA_REGISTRYINDEX );
310
+ /* }}} */
311
+
312
+ /* {{{socket compiled pattern userdata metatable */
313
+ lua_pushlightuserdata (L , & ngx_http_lua_pattern_udata_metatable_key );
314
+ lua_createtable (L , 0 /* narr */ , 1 /* nrec */ ); /* metatable */
315
+ lua_pushcfunction (L , ngx_http_lua_socket_cleanup_compiled_pattern );
316
+ lua_setfield (L , -2 , "__gc" );
317
+ lua_rawset (L , LUA_REGISTRYINDEX );
318
+ /* }}} */
283
319
}
284
320
285
321
@@ -487,9 +523,8 @@ ngx_http_lua_socket_tcp_connect(lua_State *L)
487
523
}
488
524
489
525
#if 1
490
- lua_createtable (L , 0 /* narr */ , 1 /* nrec */ ); /* metatable */
491
- lua_pushcfunction (L , ngx_http_lua_socket_tcp_upstream_destroy );
492
- lua_setfield (L , -2 , "__gc" );
526
+ lua_pushlightuserdata (L , & ngx_http_lua_upstream_udata_metatable_key );
527
+ lua_rawget (L , LUA_REGISTRYINDEX );
493
528
lua_setmetatable (L , -2 );
494
529
#endif
495
530
@@ -3015,9 +3050,8 @@ ngx_http_lua_socket_tcp_receiveuntil(lua_State *L)
3015
3050
return luaL_error (L , "no memory" );
3016
3051
}
3017
3052
3018
- lua_createtable (L , 0 /* narr */ , 1 /* nrec */ ); /* metatable */
3019
- lua_pushcfunction (L , ngx_http_lua_socket_cleanup_compiled_pattern );
3020
- lua_setfield (L , -2 , "__gc" );
3053
+ lua_pushlightuserdata (L , & ngx_http_lua_pattern_udata_metatable_key );
3054
+ lua_rawget (L , LUA_REGISTRYINDEX );
3021
3055
lua_setmetatable (L , -2 );
3022
3056
3023
3057
ngx_memzero (cp , size );
@@ -3707,9 +3741,8 @@ ngx_http_lua_req_socket(lua_State *L)
3707
3741
}
3708
3742
3709
3743
#if 1
3710
- lua_createtable (L , 0 /* narr */ , 1 /* nrec */ ); /* metatable */
3711
- lua_pushcfunction (L , ngx_http_lua_socket_downstream_destroy );
3712
- lua_setfield (L , -2 , "__gc" );
3744
+ lua_pushlightuserdata (L , & ngx_http_lua_downstream_udata_metatable_key );
3745
+ lua_rawget (L , LUA_REGISTRYINDEX );
3713
3746
lua_setmetatable (L , -2 );
3714
3747
#endif
3715
3748
@@ -3967,9 +4000,8 @@ static int ngx_http_lua_socket_tcp_setkeepalive(lua_State *L)
3967
4000
return luaL_error (L , "no memory" );
3968
4001
}
3969
4002
3970
- lua_createtable (L , 0 , 1 ); /* metatable */
3971
- lua_pushcfunction (L , ngx_http_lua_socket_shutdown_pool );
3972
- lua_setfield (L , -2 , "__gc" );
4003
+ lua_pushlightuserdata (L , & ngx_http_lua_pool_udata_metatable_key );
4004
+ lua_rawget (L , LUA_REGISTRYINDEX );
3973
4005
lua_setmetatable (L , -2 );
3974
4006
3975
4007
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , pc -> log , 0 ,
0 commit comments