diff --git a/src/main/actions_lua.c b/src/main/actions_lua.c index b29d319..648d98c 100644 --- a/src/main/actions_lua.c +++ b/src/main/actions_lua.c @@ -38,6 +38,11 @@ static int lua_action_gc(lua_State *L) { int li_lua_push_action(liServer *srv, lua_State *L, liAction *a) { liAction **pa; + if (NULL == a) { + lua_pushnil(L); + return 1; + } + pa = (liAction**) lua_newuserdata(L, sizeof(liAction*)); *pa = a; diff --git a/src/main/chunk_lua.c b/src/main/chunk_lua.c index 342c0dc..fc31f7d 100644 --- a/src/main/chunk_lua.c +++ b/src/main/chunk_lua.c @@ -290,6 +290,11 @@ liChunk* li_lua_get_chunk(lua_State *L, int ndx) { int li_lua_push_chunk(lua_State *L, liChunk *c) { liChunk **pc; + if (NULL == c) { + lua_pushnil(L); + return 1; + } + pc = (liChunk**) lua_newuserdata(L, sizeof(liChunk*)); *pc = c; @@ -316,6 +321,11 @@ liChunkQueue* li_lua_get_chunkqueue(lua_State *L, int ndx) { int li_lua_push_chunkqueue(lua_State *L, liChunkQueue *cq) { liChunkQueue **pcq; + if (NULL == cq) { + lua_pushnil(L); + return 1; + } + pcq = (liChunkQueue**) lua_newuserdata(L, sizeof(liChunkQueue*)); *pcq = cq; diff --git a/src/main/condition_lua.c b/src/main/condition_lua.c index 249bb92..2247a46 100644 --- a/src/main/condition_lua.c +++ b/src/main/condition_lua.c @@ -122,6 +122,11 @@ static void lua_push_condition_metatable(liServer *srv, lua_State *L) { int li_lua_push_condition(liServer *srv, lua_State *L, liCondition *c) { liCondition **pc; + if (NULL == c) { + lua_pushnil(L); + return 1; + } + pc = (liCondition**) lua_newuserdata(L, sizeof(liCondition*)); *pc = c; diff --git a/src/main/environment_lua.c b/src/main/environment_lua.c index faa49ca..5ba4e3c 100644 --- a/src/main/environment_lua.c +++ b/src/main/environment_lua.c @@ -139,6 +139,11 @@ liEnvironment* li_lua_get_environment(lua_State *L, int ndx) { int li_lua_push_environment(lua_State *L, liEnvironment *env) { liEnvironment **penv; + if (NULL == env) { + lua_pushnil(L); + return 1; + } + penv = (liEnvironment**) lua_newuserdata(L, sizeof(liEnvironment*)); *penv = env; diff --git a/src/main/filters_lua.c b/src/main/filters_lua.c index fc30ad7..de712e9 100644 --- a/src/main/filters_lua.c +++ b/src/main/filters_lua.c @@ -137,6 +137,11 @@ liFilter* li_lua_get_filter(lua_State *L, int ndx) { int li_lua_push_filter(lua_State *L, liFilter *f) { liFilter **pf; + if (NULL == f) { + lua_pushnil(L); + return 1; + } + pf = (liFilter**) lua_newuserdata(L, sizeof(liFilter*)); *pf = f; diff --git a/src/main/http_headers_lua.c b/src/main/http_headers_lua.c index fe6658f..dc6e749 100644 --- a/src/main/http_headers_lua.c +++ b/src/main/http_headers_lua.c @@ -227,6 +227,11 @@ liHttpHeaders* li_lua_get_http_headers(lua_State *L, int ndx) { int li_lua_push_http_headers(lua_State *L, liHttpHeaders *headers) { liHttpHeaders **pheaders; + if (NULL == headers) { + lua_pushnil(L); + return 1; + } + pheaders = (liHttpHeaders**) lua_newuserdata(L, sizeof(liHttpHeaders*)); *pheaders = headers; diff --git a/src/main/physical_lua.c b/src/main/physical_lua.c index cc165e1..627327c 100644 --- a/src/main/physical_lua.c +++ b/src/main/physical_lua.c @@ -153,6 +153,11 @@ liPhysical* li_lua_get_physical(lua_State *L, int ndx) { int li_lua_push_physical(lua_State *L, liPhysical *phys) { liPhysical **pphys; + if (NULL == phys) { + lua_pushnil(L); + return 1; + } + pphys = (liPhysical**) lua_newuserdata(L, sizeof(liPhysical*)); *pphys = phys; diff --git a/src/main/request_lua.c b/src/main/request_lua.c index 2f8a6f1..6224ce1 100644 --- a/src/main/request_lua.c +++ b/src/main/request_lua.c @@ -309,6 +309,11 @@ liRequest* li_lua_get_request(lua_State *L, int ndx) { int li_lua_push_request(lua_State *L, liRequest *req) { liRequest **preq; + if (NULL == req) { + lua_pushnil(L); + return 1; + } + preq = (liRequest**) lua_newuserdata(L, sizeof(liRequest*)); *preq = req; @@ -335,6 +340,11 @@ liRequestUri* li_lua_get_requesturi(lua_State *L, int ndx) { int li_lua_push_requesturi(lua_State *L, liRequestUri *uri) { liRequestUri **puri; + if (NULL == uri) { + lua_pushnil(L); + return 1; + } + puri = (liRequestUri**) lua_newuserdata(L, sizeof(liRequestUri*)); *puri = uri; diff --git a/src/main/response_lua.c b/src/main/response_lua.c index 6b11e2e..fc8627a 100644 --- a/src/main/response_lua.c +++ b/src/main/response_lua.c @@ -148,6 +148,11 @@ liResponse* li_lua_get_response(lua_State *L, int ndx) { int li_lua_push_response(lua_State *L, liResponse *resp) { liResponse **presp; + if (NULL == resp) { + lua_pushnil(L); + return 1; + } + presp = (liResponse**) lua_newuserdata(L, sizeof(liResponse*)); *presp = resp; diff --git a/src/main/stat_lua.c b/src/main/stat_lua.c index 77facb0..05e1051 100644 --- a/src/main/stat_lua.c +++ b/src/main/stat_lua.c @@ -220,6 +220,11 @@ void li_lua_init_stat_mt(lua_State *L) { int li_lua_push_stat(lua_State *L, struct stat *st) { struct stat *pst; + if (NULL == st) { + lua_pushnil(L); + return 1; + } + pst = (struct stat*) lua_newuserdata(L, sizeof(struct stat)); *pst = *st; diff --git a/src/main/subrequest_lua.c b/src/main/subrequest_lua.c index 0eadc7f..272411e 100644 --- a/src/main/subrequest_lua.c +++ b/src/main/subrequest_lua.c @@ -182,6 +182,11 @@ static liSubrequest* li_lua_get_subrequest(lua_State *L, int ndx) { static int li_lua_push_subrequest(lua_State *L, liSubrequest *sr) { liSubrequest **psr; + if (NULL == sr) { + lua_pushnil(L); + return 1; + } + psr = (liSubrequest**) lua_newuserdata(L, sizeof(liSubrequest*)); *psr = sr; diff --git a/src/main/virtualrequest_lua.c b/src/main/virtualrequest_lua.c index 0297cf9..1e55255 100644 --- a/src/main/virtualrequest_lua.c +++ b/src/main/virtualrequest_lua.c @@ -366,6 +366,11 @@ liVRequest* li_lua_get_vrequest(lua_State *L, int ndx) { int li_lua_push_vrequest(lua_State *L, liVRequest *vr) { liVRequest **pvr; + if (NULL == vr) { + lua_pushnil(L); + return 1; + } + pvr = (liVRequest**) lua_newuserdata(L, sizeof(liVRequest*)); *pvr = vr; @@ -513,6 +518,11 @@ liConInfo* li_lua_get_coninfo(lua_State *L, int ndx) { int li_lua_push_coninfo(lua_State *L, liConInfo *coninfo) { liConInfo **pconinfo; + if (NULL == coninfo) { + lua_pushnil(L); + return 1; + } + pconinfo = (liConInfo**) lua_newuserdata(L, sizeof(liConInfo*)); *pconinfo = coninfo; diff --git a/src/modules/mod_memcached.c b/src/modules/mod_memcached.c index da4bc23..cc8575c 100644 --- a/src/modules/mod_memcached.c +++ b/src/modules/mod_memcached.c @@ -998,6 +998,11 @@ static int lua_memcached_con_gc(lua_State *L) { static int li_lua_push_memcached_con(lua_State *L, liMemcachedCon *con) { liMemcachedCon **pcon; + if (NULL == con) { + lua_pushnil(L); + return 1; + } + pcon = (liMemcachedCon**) lua_newuserdata(L, sizeof(liMemcachedCon*)); *pcon = con; @@ -1044,6 +1049,11 @@ static int lua_memcached_req_gc(lua_State *L) { static int li_lua_push_memcached_req(lua_State *L, mc_lua_request *req) { mc_lua_request **preq; + if (NULL == req) { + lua_pushnil(L); + return 1; + } + preq = (mc_lua_request**) lua_newuserdata(L, sizeof(mc_lua_request*)); *preq = req;