Browse Source

[lua] one li_lua_init_*_mt function per "file", add a few missing ones

Change-Id: I95661db55debe76c0aca99b2920ce202af7d9967
personal/stbuehler/freebsd-3071
Stefan Bühler 3 months ago
parent
commit
5977493f47
  1. 2
      include/lighttpd/actions_lua.h
  2. 2
      include/lighttpd/condition_lua.h
  3. 28
      include/lighttpd/core_lua.h
  4. 2
      include/lighttpd/value_lua.h
  5. 5
      src/main/actions_lua.c
  6. 11
      src/main/condition_lua.c
  7. 16
      src/main/core_lua.c
  8. 4
      src/main/value_lua.c
  9. 10
      src/main/virtualrequest_lua.c

2
include/lighttpd/actions_lua.h

@ -4,6 +4,8 @@
#include <lighttpd/base.h>
#include <lua.h>
LI_API void li_lua_init_action_mt(liServer *srv, lua_State *L);
LI_API liAction* li_lua_get_action(lua_State *L, int ndx);
LI_API int li_lua_push_action(liServer *srv, lua_State *L, liAction *a);

2
include/lighttpd/condition_lua.h

@ -4,6 +4,8 @@
#include <lighttpd/base.h>
#include <lua.h>
LI_API void li_lua_init_condition_mt(liServer *srv, lua_State *L);
LI_API liCondition* li_lua_get_condition(lua_State *L, int ndx);
LI_API int li_lua_push_condition(liServer *srv, lua_State *L, liCondition *c);

28
include/lighttpd/core_lua.h

@ -14,20 +14,21 @@ LI_API liLuaState *li_lua_state_get(lua_State *L);
INLINE void li_lua_lock(liLuaState *LL);
INLINE void li_lua_unlock(liLuaState *LL);
/* chunk_lua.c */
LI_API void li_lua_init_chunk_mt(lua_State *L);
LI_API liChunk* li_lua_get_chunk(lua_State *L, int ndx);
LI_API int li_lua_push_chunk(lua_State *L, liChunk *c);
LI_API liChunkQueue* li_lua_get_chunkqueue(lua_State *L, int ndx);
LI_API int li_lua_push_chunkqueue(lua_State *L, liChunkQueue *cq);
LI_API void li_lua_init_connection_mt(lua_State *L);
LI_API liConnection* li_lua_get_connection(lua_State *L, int ndx);
LI_API int li_lua_push_connection(lua_State *L, liConnection *con);
/* environment_lua.c */
LI_API void li_lua_init_environment_mt(lua_State *L);
LI_API liEnvironment* li_lua_get_environment(lua_State *L, int ndx);
LI_API int li_lua_push_environment(lua_State *L, liEnvironment *env);
/* filters_lua.c */
LI_API void li_lua_init_filter_mt(lua_State *L);
LI_API liFilter* li_lua_get_filter(lua_State *L, int ndx);
LI_API int li_lua_push_filter(lua_State *L, liFilter *f);
@ -35,44 +36,57 @@ LI_API void li_lua_init_filters(lua_State *L, liServer* srv);
LI_API liFilter* li_lua_vrequest_add_filter_in(lua_State *L, liVRequest *vr, int state_ndx);
LI_API liFilter* li_lua_vrequest_add_filter_out(lua_State *L, liVRequest *vr, int state_ndx);
/* http_headers_lua.c */
LI_API void li_lua_init_http_headers_mt(lua_State *L);
LI_API liHttpHeaders* li_lua_get_http_headers(lua_State *L, int ndx);
LI_API int li_lua_push_http_headers(lua_State *L, liHttpHeaders *headers);
/* physical_lua.c */
LI_API void li_lua_init_physical_mt(lua_State *L);
LI_API liPhysical* li_lua_get_physical(lua_State *L, int ndx);
LI_API int li_lua_push_physical(lua_State *L, liPhysical *phys);
/* request_lua.c */
LI_API void li_lua_init_request_mt(lua_State *L);
LI_API liRequest* li_lua_get_request(lua_State *L, int ndx);
LI_API int li_lua_push_request(lua_State *L, liRequest *req);
LI_API liRequestUri* li_lua_get_requesturi(lua_State *L, int ndx);
LI_API int li_lua_push_requesturi(lua_State *L, liRequestUri *uri);
/* response_lua.c */
LI_API void li_lua_init_response_mt(lua_State *L);
LI_API liResponse* li_lua_get_response(lua_State *L, int ndx);
LI_API int li_lua_push_response(lua_State *L, liResponse *resp);
/* stat_lua.c */
LI_API void li_lua_init_stat_mt(lua_State *L);
LI_API struct stat* li_lua_get_stat(lua_State *L, int ndx);
LI_API int li_lua_push_stat(lua_State *L, struct stat *st);
/* subrequest_lua.c */
LI_API void li_lua_init_subrequest_mt(lua_State *L);
LI_API void li_lua_init_vrequest_mt(lua_State *L);
/* virtualrequest_lua.c */
LI_API void li_lua_init_virtualrequest_mt(lua_State *L);
LI_API liVRequest* li_lua_get_vrequest(lua_State *L, int ndx);
LI_API int li_lua_push_vrequest(lua_State *L, liVRequest *vr);
LI_API void li_lua_init_coninfo_mt(lua_State *L);
LI_API liConInfo* li_lua_get_coninfo(lua_State *L, int ndx);
LI_API int li_lua_push_coninfo(lua_State *L, liConInfo *vr);
/* everything else: core_lua.c */
LI_API int li_lua_fixindex(lua_State *L, int ndx);
/* return 1 if value is found in mt (on top of the stack), 0 if it is not found (stack balance = 0)
* table, key on stack at pos 0 and 1 (i.e. __index metho)
* table, key on stack at pos 0 and 1 (i.e. __index method)
*/
LI_API int li_lua_metatable_index(lua_State *L);

2
include/lighttpd/value_lua.h

@ -4,6 +4,8 @@
#include <lighttpd/base.h>
#include <lua.h>
LI_API void li_lua_init_value_mt(lua_State *L);
/* converts the top of the stack into an value
* and pops the value
* returns NULL if it couldn't convert the value (still pops it)

5
src/main/actions_lua.c

@ -35,6 +35,11 @@ static void lua_push_action_metatable(liServer *srv, lua_State *L) {
}
}
void li_lua_init_action_mt(liServer *srv, lua_State *L) {
lua_push_action_metatable(srv, L);
lua_pop(L, 1);
}
liAction* li_lua_get_action(lua_State *L, int ndx) {
if (!lua_isuserdata(L, ndx)) return NULL;
if (!lua_getmetatable(L, ndx)) return NULL;

11
src/main/condition_lua.c

@ -269,6 +269,17 @@ static void lua_push_cond_lvalue_t_metatable(liServer *srv, lua_State *L) {
}
}
void li_lua_init_condition_mt(liServer *srv, lua_State *L) {
lua_push_condition_metatable(srv, L);
lua_pop(L, 1);
lua_push_cond_lvalue_metatable(srv, L);
lua_pop(L, 1);
lua_push_cond_lvalue_t_metatable(srv, L);
lua_pop(L, 1);
}
/* cond_lvalue_t */
static int lua_push_cond_lvalue_t(liServer *srv, lua_State *L, liCondLValue t) {

16
src/main/core_lua.c

@ -1,5 +1,8 @@
#include <lighttpd/core_lua.h>
#include <lighttpd/actions_lua.h>
#include <lighttpd/condition_lua.h>
#include <lighttpd/value_lua.h>
#include <lualib.h>
#include <lauxlib.h>
@ -330,15 +333,22 @@ void li_lua_init2(liLuaState *LL, liServer *srv, liWorker *wrk) {
lua_State *L = LL->L;
li_lua_init_chunk_mt(L);
li_lua_init_coninfo_mt(L);
li_lua_init_environment_mt(L);
li_lua_init_filter_mt(L);
li_lua_init_http_headers_mt(L);
li_lua_init_physical_mt(L);
li_lua_init_request_mt(L);
li_lua_init_response_mt(L);
li_lua_init_vrequest_mt(L);
li_lua_init_stat_mt(L);
li_lua_init_subrequest_mt(L);
li_lua_init_virtualrequest_mt(L);
if (NULL == wrk) {
/* these should only be used in the "main" lua context */
li_lua_init_action_mt(srv, L);
li_lua_init_condition_mt(srv, L);
li_lua_init_value_mt(L);
}
/* prefer closure, but just in case */
lua_pushlightuserdata(L, srv);

4
src/main/value_lua.c

@ -68,6 +68,10 @@ static void lua_push_kvlist_metatable(lua_State *L) {
}
}
void li_lua_init_value_mt(lua_State *L) {
lua_push_kvlist_metatable(L);
lua_pop(L, 1);
}
static liValue* li_value_from_lua_table(liServer *srv, lua_State *L, int ndx) {
liValue *val, *entry;

10
src/main/virtualrequest_lua.c

@ -350,11 +350,6 @@ static void lua_push_vrequest_metatable(lua_State *L) {
}
}
void li_lua_init_vrequest_mt(lua_State *L) {
lua_push_vrequest_metatable(L);
lua_pop(L, 1);
}
liVRequest* li_lua_get_vrequest(lua_State *L, int ndx) {
if (!lua_isuserdata(L, ndx)) return NULL;
if (!lua_getmetatable(L, ndx)) return NULL;
@ -503,7 +498,10 @@ static void lua_push_coninfo_metatable(lua_State *L) {
}
}
void li_lua_init_coninfo_mt(lua_State *L) {
void li_lua_init_virtualrequest_mt(lua_State *L) {
lua_push_vrequest_metatable(L);
lua_pop(L, 1);
lua_push_coninfo_metatable(L);
lua_pop(L, 1);
}

Loading…
Cancel
Save