[lua] check values for NULL before pushing to stack

personal/stbuehler/wip
Stefan Bühler 10 years ago
parent b1611a2047
commit f33a7fd3fa

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

Loading…
Cancel
Save