Browse Source

[lua] split all metatable init/create code into separate functions

- lua_push_*_metatable and init_*_mt (init only used by push)

Change-Id: I42a3d58b884205f30e4ee9a99c693ce65e9dbf66
personal/stbuehler/freebsd-3071
Stefan Bühler 3 months ago
parent
commit
7aec09dd27
  1. 43
      src/main/actions_lua.c
  2. 35
      src/main/chunk_lua.c
  3. 67
      src/main/condition_lua.c
  4. 13
      src/main/environment_lua.c
  5. 13
      src/main/filters_lua.c
  6. 13
      src/main/http_headers_lua.c
  7. 13
      src/main/physical_lua.c
  8. 34
      src/main/request_lua.c
  9. 13
      src/main/response_lua.c
  10. 13
      src/main/stat_lua.c
  11. 13
      src/main/subrequest_lua.c
  12. 10
      src/main/value_lua.c
  13. 26
      src/main/virtualrequest_lua.c
  14. 34
      src/modules/mod_memcached.c

43
src/main/actions_lua.c

@ -8,18 +8,6 @@
#define LUA_ACTION "liAction*"
liAction* li_lua_get_action(lua_State *L, int ndx) {
if (!lua_isuserdata(L, ndx)) return NULL;
if (!lua_getmetatable(L, ndx)) return NULL;
luaL_getmetatable(L, LUA_ACTION);
if (lua_isnil(L, -1) || lua_isnil(L, -2) || !lua_equal(L, -1, -2)) {
lua_pop(L, 2);
return NULL;
}
lua_pop(L, 2);
return *(liAction**) lua_touserdata(L, ndx);
}
static int lua_action_gc(lua_State *L) {
liServer *srv;
liLuaState *LL = li_lua_state_get(L);
@ -35,6 +23,30 @@ static int lua_action_gc(lua_State *L) {
return 0;
}
static HEDLEY_NEVER_INLINE void init_action_mt(liServer *srv, lua_State *L) {
lua_pushlightuserdata(L, srv);
lua_pushcclosure(L, lua_action_gc, 1);
lua_setfield(L, -2, "__gc");
}
static void lua_push_action_metatable(liServer *srv, lua_State *L) {
if (luaL_newmetatable(L, LUA_ACTION)) {
init_action_mt(srv, L);
}
}
liAction* li_lua_get_action(lua_State *L, int ndx) {
if (!lua_isuserdata(L, ndx)) return NULL;
if (!lua_getmetatable(L, ndx)) return NULL;
luaL_getmetatable(L, LUA_ACTION);
if (lua_isnil(L, -1) || lua_isnil(L, -2) || !lua_equal(L, -1, -2)) {
lua_pop(L, 2);
return NULL;
}
lua_pop(L, 2);
return *(liAction**) lua_touserdata(L, ndx);
}
int li_lua_push_action(liServer *srv, lua_State *L, liAction *a) {
liAction **pa;
@ -46,12 +58,7 @@ int li_lua_push_action(liServer *srv, lua_State *L, liAction *a) {
pa = (liAction**) lua_newuserdata(L, sizeof(liAction*));
*pa = a;
if (luaL_newmetatable(L, LUA_ACTION)) {
lua_pushlightuserdata(L, srv);
lua_pushcclosure(L, lua_action_gc, 1);
lua_setfield(L, -2, "__gc");
}
lua_push_action_metatable(srv, L);
lua_setmetatable(L, -2);
return 1;
}

35
src/main/chunk_lua.c

@ -9,8 +9,15 @@
#define LUA_CHUNK "liChunk*"
#define LUA_CHUNKQUEUE "liChunkQueue*"
static void init_chunk_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_chunk_mt(lua_State *L) {
/* TODO */
UNUSED(L);
}
static void lua_push_chunk_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_CHUNK)) {
init_chunk_mt(L);
}
}
typedef int (*lua_ChunkQueue_Attrib)(liChunkQueue *cq, lua_State *L);
@ -259,19 +266,21 @@ static const luaL_Reg chunkqueue_mt[] = {
{ NULL, NULL }
};
static void init_chunkqueue_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_chunkqueue_mt(lua_State *L) {
luaL_register(L, NULL, chunkqueue_mt);
}
void li_lua_init_chunk_mt(lua_State *L) {
if (luaL_newmetatable(L, LUA_CHUNK)) {
init_chunk_mt(L);
}
lua_pop(L, 1);
static void lua_push_chunkqueue_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_CHUNKQUEUE)) {
init_chunkqueue_mt(L);
}
}
void li_lua_init_chunk_mt(lua_State *L) {
lua_push_chunk_metatable(L);
lua_pop(L, 1);
lua_push_chunkqueue_metatable(L);
lua_pop(L, 1);
}
@ -298,10 +307,7 @@ int li_lua_push_chunk(lua_State *L, liChunk *c) {
pc = (liChunk**) lua_newuserdata(L, sizeof(liChunk*));
*pc = c;
if (luaL_newmetatable(L, LUA_CHUNK)) {
init_chunk_mt(L);
}
lua_push_chunk_metatable(L);
lua_setmetatable(L, -2);
return 1;
}
@ -329,10 +335,7 @@ int li_lua_push_chunkqueue(lua_State *L, liChunkQueue *cq) {
pcq = (liChunkQueue**) lua_newuserdata(L, sizeof(liChunkQueue*));
*pcq = cq;
if (luaL_newmetatable(L, LUA_CHUNKQUEUE)) {
init_chunkqueue_mt(L);
}
lua_push_chunkqueue_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

67
src/main/condition_lua.c

@ -113,9 +113,13 @@ static int lua_cond_lvalue_gc(lua_State *L) {
/* new metatables and push */
static HEDLEY_NEVER_INLINE void init_condition_mt(liServer *srv, lua_State *L) {
lua_mt_register_srv(srv, L, "__gc", lua_condition_gc);
}
static void lua_push_condition_metatable(liServer *srv, lua_State *L) {
if (luaL_newmetatable(L, LUA_CONDITION)) {
lua_mt_register_srv(srv, L, "__gc", lua_condition_gc);
init_condition_mt(srv, L);
}
}
@ -131,7 +135,6 @@ int li_lua_push_condition(liServer *srv, lua_State *L, liCondition *c) {
*pc = c;
lua_push_condition_metatable(srv, L);
lua_setmetatable(L, -2);
return 1;
}
@ -193,31 +196,35 @@ static int lua_cond_lvalue_cmp(lua_State *L) {
return 0;
}
static HEDLEY_NEVER_INLINE void init_cond_lvalue_mt(liServer *srv, lua_State *L) {
lua_mt_register(L, "__gc", lua_cond_lvalue_gc);
lua_mt_register(L, "__tostring", lua_cond_lvalue_tostring);
lua_mt_register_cmp(srv, L, "eq", lua_cond_lvalue_cmp, LI_CONFIG_COND_EQ);
lua_mt_register_cmp(srv, L, "ne", lua_cond_lvalue_cmp, LI_CONFIG_COND_NE);
lua_mt_register_cmp(srv, L, "prefix", lua_cond_lvalue_cmp, LI_CONFIG_COND_PREFIX);
lua_mt_register_cmp(srv, L, "notprefix", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOPREFIX);
lua_mt_register_cmp(srv, L, "suffix", lua_cond_lvalue_cmp, LI_CONFIG_COND_SUFFIX);
lua_mt_register_cmp(srv, L, "notsuffix", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOSUFFIX);
lua_mt_register_cmp(srv, L, "match", lua_cond_lvalue_cmp, LI_CONFIG_COND_MATCH);
lua_mt_register_cmp(srv, L, "nomatch", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOMATCH);
lua_mt_register_cmp(srv, L, "ip", lua_cond_lvalue_cmp, LI_CONFIG_COND_IP);
lua_mt_register_cmp(srv, L, "notip", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOTIP);
lua_mt_register_cmp(srv, L, "gt", lua_cond_lvalue_cmp, LI_CONFIG_COND_GT);
lua_mt_register_cmp(srv, L, "ge", lua_cond_lvalue_cmp, LI_CONFIG_COND_GE);
lua_mt_register_cmp(srv, L, "lt", lua_cond_lvalue_cmp, LI_CONFIG_COND_LT);
lua_mt_register_cmp(srv, L, "le", lua_cond_lvalue_cmp, LI_CONFIG_COND_LE);
lua_mt_register_cmp(srv, L, "is", lua_cond_lvalue_bool, LI_CONFIG_COND_EQ);
lua_mt_register_cmp(srv, L, "isnot", lua_cond_lvalue_bool, LI_CONFIG_COND_NE);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
}
static void lua_push_cond_lvalue_metatable(liServer *srv, lua_State *L) {
if (luaL_newmetatable(L, LUA_COND_LVALUE)) {
lua_mt_register(L, "__gc", lua_cond_lvalue_gc);
lua_mt_register(L, "__tostring", lua_cond_lvalue_tostring);
lua_mt_register_cmp(srv, L, "eq", lua_cond_lvalue_cmp, LI_CONFIG_COND_EQ);
lua_mt_register_cmp(srv, L, "ne", lua_cond_lvalue_cmp, LI_CONFIG_COND_NE);
lua_mt_register_cmp(srv, L, "prefix", lua_cond_lvalue_cmp, LI_CONFIG_COND_PREFIX);
lua_mt_register_cmp(srv, L, "notprefix", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOPREFIX);
lua_mt_register_cmp(srv, L, "suffix", lua_cond_lvalue_cmp, LI_CONFIG_COND_SUFFIX);
lua_mt_register_cmp(srv, L, "notsuffix", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOSUFFIX);
lua_mt_register_cmp(srv, L, "match", lua_cond_lvalue_cmp, LI_CONFIG_COND_MATCH);
lua_mt_register_cmp(srv, L, "nomatch", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOMATCH);
lua_mt_register_cmp(srv, L, "ip", lua_cond_lvalue_cmp, LI_CONFIG_COND_IP);
lua_mt_register_cmp(srv, L, "notip", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOTIP);
lua_mt_register_cmp(srv, L, "gt", lua_cond_lvalue_cmp, LI_CONFIG_COND_GT);
lua_mt_register_cmp(srv, L, "ge", lua_cond_lvalue_cmp, LI_CONFIG_COND_GE);
lua_mt_register_cmp(srv, L, "lt", lua_cond_lvalue_cmp, LI_CONFIG_COND_LT);
lua_mt_register_cmp(srv, L, "le", lua_cond_lvalue_cmp, LI_CONFIG_COND_LE);
lua_mt_register_cmp(srv, L, "is", lua_cond_lvalue_bool, LI_CONFIG_COND_EQ);
lua_mt_register_cmp(srv, L, "isnot", lua_cond_lvalue_bool, LI_CONFIG_COND_NE);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
init_cond_lvalue_mt(srv, L);
}
}
@ -228,7 +235,6 @@ static int lua_push_cond_lvalue(liServer *srv, lua_State *L, liConditionLValue *
*pv = lvalue;
lua_push_cond_lvalue_metatable(srv, L);
lua_setmetatable(L, -2);
return 1;
}
@ -252,10 +258,14 @@ static int lua_cond_lvalue_t_index(lua_State *L) {
return 1;
}
static HEDLEY_NEVER_INLINE void init_cond_lvalue_t_mt(liServer *srv, lua_State *L) {
lua_mt_register(L, "__tostring", lua_cond_lvalue_t_tostring);
lua_mt_register_srv(srv, L, "__index", lua_cond_lvalue_t_index);
}
static void lua_push_cond_lvalue_t_metatable(liServer *srv, lua_State *L) {
if (luaL_newmetatable(L, LUA_COND_LVALUE_T)) {
lua_mt_register(L, "__tostring", lua_cond_lvalue_t_tostring);
lua_mt_register_srv(srv, L, "__index", lua_cond_lvalue_t_index);
init_cond_lvalue_t_mt(srv, L);
}
}
@ -268,7 +278,6 @@ static int lua_push_cond_lvalue_t(liServer *srv, lua_State *L, liCondLValue t) {
*pt = t;
lua_push_cond_lvalue_t_metatable(srv, L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/environment_lua.c

@ -113,14 +113,18 @@ static const luaL_Reg environment_mt[] = {
{ NULL, NULL }
};
static void init_env_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_env_mt(lua_State *L) {
luaL_register(L, NULL, environment_mt);
}
void li_lua_init_environment_mt(lua_State *L) {
static void lua_push_environment_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_ENVIRONMENT)) {
init_env_mt(L);
}
}
void li_lua_init_environment_mt(lua_State *L) {
lua_push_environment_metatable(L);
lua_pop(L, 1);
}
@ -147,10 +151,7 @@ int li_lua_push_environment(lua_State *L, liEnvironment *env) {
penv = (liEnvironment**) lua_newuserdata(L, sizeof(liEnvironment*));
*penv = env;
if (luaL_newmetatable(L, LUA_ENVIRONMENT)) {
init_env_mt(L);
}
lua_push_environment_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/filters_lua.c

@ -111,14 +111,18 @@ static const luaL_Reg filter_mt[] = {
{ NULL, NULL }
};
static void init_filter_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_filter_mt(lua_State *L) {
luaL_register(L, NULL, filter_mt);
}
void li_lua_init_filter_mt(lua_State *L) {
static void lua_push_filter_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_FILTER)) {
init_filter_mt(L);
}
}
void li_lua_init_filter_mt(lua_State *L) {
lua_push_filter_metatable(L);
lua_pop(L, 1);
}
@ -145,10 +149,7 @@ int li_lua_push_filter(lua_State *L, liFilter *f) {
pf = (liFilter**) lua_newuserdata(L, sizeof(liFilter*));
*pf = f;
if (luaL_newmetatable(L, LUA_FILTER)) {
init_filter_mt(L);
}
lua_push_filter_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/http_headers_lua.c

@ -201,14 +201,18 @@ static const luaL_Reg http_headers_mt[] = {
{ NULL, NULL }
};
static void init_http_headers_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_http_headers_mt(lua_State *L) {
luaL_register(L, NULL, http_headers_mt);
}
void li_lua_init_http_headers_mt(lua_State *L) {
static void lua_push_http_headers_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_HTTPHEADERS)) {
init_http_headers_mt(L);
}
}
void li_lua_init_http_headers_mt(lua_State *L) {
lua_push_http_headers_metatable(L);
lua_pop(L, 1);
}
@ -235,10 +239,7 @@ int li_lua_push_http_headers(lua_State *L, liHttpHeaders *headers) {
pheaders = (liHttpHeaders**) lua_newuserdata(L, sizeof(liHttpHeaders*));
*pheaders = headers;
if (luaL_newmetatable(L, LUA_HTTPHEADERS)) {
init_http_headers_mt(L);
}
lua_push_http_headers_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/physical_lua.c

@ -127,14 +127,18 @@ static const luaL_Reg physical_mt[] = {
{ NULL, NULL }
};
static void init_physical_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_physical_mt(lua_State *L) {
luaL_register(L, NULL, physical_mt);
}
void li_lua_init_physical_mt(lua_State *L) {
static void lua_push_physical_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_PHYSICAL)) {
init_physical_mt(L);
}
}
void li_lua_init_physical_mt(lua_State *L) {
lua_push_physical_metatable(L);
lua_pop(L, 1);
}
@ -161,10 +165,7 @@ int li_lua_push_physical(lua_State *L, liPhysical *phys) {
pphys = (liPhysical**) lua_newuserdata(L, sizeof(liPhysical*));
*pphys = phys;
if (luaL_newmetatable(L, LUA_PHYSICAL)) {
init_physical_mt(L);
}
lua_push_physical_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

34
src/main/request_lua.c

@ -143,10 +143,16 @@ static const luaL_Reg request_mt[] = {
{ NULL, NULL }
};
static void init_request_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_request_mt(lua_State *L) {
luaL_register(L, NULL, request_mt);
}
static void lua_push_request_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_REQUEST)) {
init_request_mt(L);
}
}
typedef int (*lua_RequestUri_Attrib)(liRequestUri *uri, lua_State *L);
#define DEF_LUA_MODIFY_GSTRING(attr) \
@ -278,19 +284,21 @@ static const luaL_Reg requesturi_mt[] = {
{ NULL, NULL }
};
static void init_requesturi_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_requesturi_mt(lua_State *L) {
luaL_register(L, NULL, requesturi_mt);
}
void li_lua_init_request_mt(lua_State *L) {
if (luaL_newmetatable(L, LUA_REQUEST)) {
init_request_mt(L);
}
lua_pop(L, 1);
static void lua_push_requesturi_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_REQUESTURI)) {
init_requesturi_mt(L);
}
}
void li_lua_init_request_mt(lua_State *L) {
lua_push_request_metatable(L);
lua_pop(L, 1);
lua_push_requesturi_metatable(L);
lua_pop(L, 1);
}
@ -317,10 +325,7 @@ int li_lua_push_request(lua_State *L, liRequest *req) {
preq = (liRequest**) lua_newuserdata(L, sizeof(liRequest*));
*preq = req;
if (luaL_newmetatable(L, LUA_REQUEST)) {
init_request_mt(L);
}
lua_push_request_metatable(L);
lua_setmetatable(L, -2);
return 1;
}
@ -348,10 +353,7 @@ int li_lua_push_requesturi(lua_State *L, liRequestUri *uri) {
puri = (liRequestUri**) lua_newuserdata(L, sizeof(liRequestUri*));
*puri = uri;
if (luaL_newmetatable(L, LUA_REQUESTURI)) {
init_requesturi_mt(L);
}
lua_push_requesturi_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/response_lua.c

@ -122,14 +122,18 @@ static const luaL_Reg response_mt[] = {
{ NULL, NULL }
};
static void init_response_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_response_mt(lua_State *L) {
luaL_register(L, NULL, response_mt);
}
void li_lua_init_response_mt(lua_State *L) {
static void lua_push_response_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_RESPONSE)) {
init_response_mt(L);
}
}
void li_lua_init_response_mt(lua_State *L) {
lua_push_response_metatable(L);
lua_pop(L, 1);
}
@ -156,10 +160,7 @@ int li_lua_push_response(lua_State *L, liResponse *resp) {
presp = (liResponse**) lua_newuserdata(L, sizeof(liResponse*));
*presp = resp;
if (luaL_newmetatable(L, LUA_RESPONSE)) {
init_response_mt(L);
}
lua_push_response_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/stat_lua.c

@ -206,14 +206,18 @@ static const luaL_Reg stat_mt[] = {
{ NULL, NULL }
};
static void init_stat_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_stat_mt(lua_State *L) {
luaL_register(L, NULL, stat_mt);
}
void li_lua_init_stat_mt(lua_State *L) {
static void lua_push_stat_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_STAT)) {
init_stat_mt(L);
}
}
void li_lua_init_stat_mt(lua_State *L) {
lua_push_stat_metatable(L);
lua_pop(L, 1);
}
@ -228,10 +232,7 @@ int li_lua_push_stat(lua_State *L, struct stat *st) {
pst = (struct stat*) lua_newuserdata(L, sizeof(struct stat));
*pst = *st;
if (luaL_newmetatable(L, LUA_STAT)) {
init_stat_mt(L);
}
lua_push_stat_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

13
src/main/subrequest_lua.c

@ -156,14 +156,18 @@ static const luaL_Reg subrequest_mt[] = {
};
static void init_subrequest_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_subrequest_mt(lua_State *L) {
luaL_register(L, NULL, subrequest_mt);
}
void li_lua_init_subrequest_mt(lua_State *L) {
static void lua_push_subrequest_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_SUBREQUEST)) {
init_subrequest_mt(L);
}
}
void li_lua_init_subrequest_mt(lua_State *L) {
lua_push_subrequest_metatable(L);
lua_pop(L, 1);
}
@ -190,10 +194,7 @@ static int li_lua_push_subrequest(lua_State *L, liSubrequest *sr) {
psr = (liSubrequest**) lua_newuserdata(L, sizeof(liSubrequest*));
*psr = sr;
if (luaL_newmetatable(L, LUA_SUBREQUEST)) {
init_subrequest_mt(L);
}
lua_push_subrequest_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

10
src/main/value_lua.c

@ -57,10 +57,14 @@ fail:
return 1;
}
static HEDLEY_NEVER_INLINE void init_kvlist_mt(lua_State *L) {
lua_pushcclosure(L, lua_kvlist_index, 0);
lua_setfield(L, -2, "__index");
}
static void lua_push_kvlist_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_KVLIST_VALUE)) {
lua_pushcclosure(L, lua_kvlist_index, 0);
lua_setfield(L, -2, "__index");
init_kvlist_mt(L);
}
}
@ -107,7 +111,7 @@ static liValue* li_value_from_lua_table(liServer *srv, lua_State *L, int ndx) {
break;
default:
ERROR(srv, "Unexpted key type in table: %s (%i) - skipping entry", lua_typename(L, lua_type(L, -1)), lua_type(L, -1));
ERROR(srv, "Unexpected key type in table: %s (%i) - skipping entry", lua_typename(L, lua_type(L, -1)), lua_type(L, -1));
lua_pop(L, 1);
break;
}

26
src/main/virtualrequest_lua.c

@ -340,14 +340,18 @@ static const luaL_Reg vrequest_mt[] = {
{ NULL, NULL }
};
static void init_vrequest_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_vrequest_mt(lua_State *L) {
luaL_register(L, NULL, vrequest_mt);
}
void li_lua_init_vrequest_mt(lua_State *L) {
static void lua_push_vrequest_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_VREQUEST)) {
init_vrequest_mt(L);
}
}
void li_lua_init_vrequest_mt(lua_State *L) {
lua_push_vrequest_metatable(L);
lua_pop(L, 1);
}
@ -374,10 +378,7 @@ int li_lua_push_vrequest(lua_State *L, liVRequest *vr) {
pvr = (liVRequest**) lua_newuserdata(L, sizeof(liVRequest*));
*pvr = vr;
if (luaL_newmetatable(L, LUA_VREQUEST)) {
init_vrequest_mt(L);
}
lua_push_vrequest_metatable(L);
lua_setmetatable(L, -2);
return 1;
}
@ -492,14 +493,18 @@ static const luaL_Reg coninfo_mt[] = {
{ NULL, NULL }
};
static void init_coninfo_mt(lua_State *L) {
static HEDLEY_NEVER_INLINE void init_coninfo_mt(lua_State *L) {
luaL_register(L, NULL, coninfo_mt);
}
void li_lua_init_coninfo_mt(lua_State *L) {
static void lua_push_coninfo_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_CONINFO)) {
init_coninfo_mt(L);
}
}
void li_lua_init_coninfo_mt(lua_State *L) {
lua_push_coninfo_metatable(L);
lua_pop(L, 1);
}
@ -526,10 +531,7 @@ int li_lua_push_coninfo(lua_State *L, liConInfo *coninfo) {
pconinfo = (liConInfo**) lua_newuserdata(L, sizeof(liConInfo*));
*pconinfo = coninfo;
if (luaL_newmetatable(L, LUA_CONINFO)) {
init_coninfo_mt(L);
}
lua_push_coninfo_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

34
src/modules/mod_memcached.c

@ -913,6 +913,18 @@ static const luaL_Reg mc_con_mt[] = {
{ NULL, NULL }
};
static HEDLEY_NEVER_INLINE void init_mc_con_mt(lua_State *L) {
luaL_register(L, NULL, mc_con_mt);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
}
static void lua_push_mc_con_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_MEMCACHEDCON)) {
init_mc_con_mt(L);
}
}
typedef int (*lua_mc_req_Attrib)(mc_lua_request *req, lua_State *L);
static int lua_mc_req_attr_read_response(mc_lua_request *req, lua_State *L) {
@ -980,14 +992,14 @@ static const luaL_Reg mc_req_mt[] = {
{ NULL, NULL }
};
static void init_mc_con_mt(lua_State *L) {
luaL_register(L, NULL, mc_con_mt);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
static HEDLEY_NEVER_INLINE void init_mc_req_mt(lua_State *L) {
luaL_register(L, NULL, mc_req_mt);
}
static void init_mc_req_mt(lua_State *L) {
luaL_register(L, NULL, mc_req_mt);
static void lua_push_mc_req_metatable(lua_State *L) {
if (luaL_newmetatable(L, LUA_MEMCACHEDREQUEST)) {
init_mc_req_mt(L);
}
}
static liMemcachedCon* li_lua_get_memcached_con(lua_State *L, int ndx) {
@ -1021,10 +1033,7 @@ static int li_lua_push_memcached_con(lua_State *L, liMemcachedCon *con) {
pcon = (liMemcachedCon**) lua_newuserdata(L, sizeof(liMemcachedCon*));
*pcon = con;
if (luaL_newmetatable(L, LUA_MEMCACHEDCON)) {
init_mc_con_mt(L);
}
lua_push_mc_con_metatable(L);
lua_setmetatable(L, -2);
return 1;
}
@ -1072,10 +1081,7 @@ static int li_lua_push_memcached_req(lua_State *L, mc_lua_request *req) {
preq = (mc_lua_request**) lua_newuserdata(L, sizeof(mc_lua_request*));
*preq = req;
if (luaL_newmetatable(L, LUA_MEMCACHEDREQUEST)) {
init_mc_req_mt(L);
}
lua_push_mc_req_metatable(L);
lua_setmetatable(L, -2);
return 1;
}

Loading…
Cancel
Save