Add "include_lua" to config special commands if compiled with lua

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent 0320330685
commit 39a879f89a
  1. 2
      include/lighttpd/config_lua.h
  2. 36
      src/main/config_lua.c
  3. 29
      src/main/config_parser.rl
  4. 2
      src/main/lighttpd.c

@ -3,6 +3,6 @@
#include <lighttpd/base.h>
LI_API gboolean li_config_lua_load(liServer *srv, const gchar *filename);
LI_API gboolean li_config_lua_load(liServer *srv, const gchar *filename, liAction **pact);
#endif

@ -141,10 +141,14 @@ static int handle_server_action(liServer *srv, lua_State *L, gpointer _sa) {
lua_checkstack(L, 16);
val = lua_params_to_value(srv, L);
li_lua_unlock(srv);
/* TRACE(srv, "%s", "Creating action"); */
a = sa->li_create_action(srv, sa->p, val);
li_value_free(val);
li_lua_lock(srv);
if (NULL == a) {
lua_pushstring(L, "creating action failed");
lua_error(L);
@ -156,13 +160,17 @@ static int handle_server_action(liServer *srv, lua_State *L, gpointer _sa) {
static int handle_server_setup(liServer *srv, lua_State *L, gpointer _ss) {
liServerSetup *ss = (liServerSetup*) _ss;
liValue *val;
gboolean res;
lua_checkstack(L, 16);
val = lua_params_to_value(srv, L);
li_lua_unlock(srv);
/* TRACE(srv, "%s", "Calling setup"); */
res = ss->setup(srv, ss->p, val);
li_lua_lock(srv);
if (!ss->setup(srv, ss->p, val)) {
if (!res) {
li_value_free(val);
lua_pushstring(L, "setup failed");
lua_error(L);
@ -172,12 +180,17 @@ static int handle_server_setup(liServer *srv, lua_State *L, gpointer _ss) {
return 0;
}
gboolean li_config_lua_load(liServer *srv, const gchar *filename) {
gboolean li_config_lua_load(liServer *srv, const gchar *filename, liAction **pact) {
lua_State *L = srv->L;
int errfunc;
int lua_stack_top;
*pact = NULL;
li_lua_lock(srv);
lua_stack_top = lua_gettop(L);
li_lua_new_globals(L);
if (0 != luaL_loadfile(L, filename)) {
@ -204,12 +217,23 @@ gboolean li_config_lua_load(liServer *srv, const gchar *filename) {
lua_pop(L, 1); /* pop the ret-value */
lua_getfield(L, LUA_GLOBALSINDEX, "actions");
srv->mainaction = lua_get_action(L, -1);
li_action_acquire(srv->mainaction);
{
liAction *act;
lua_getfield(L, LUA_GLOBALSINDEX, "actions");
act = lua_get_action(L, -1);
if (NULL == act && lua_isfunction(L, -1)) {
act = lua_make_action(srv, L, -1);
}
if (act != NULL) {
li_action_acquire(act);
*pact = act;
}
}
lua_pop(L, 1);
assert(lua_gettop(L) == 0);
assert(lua_gettop(L) == lua_stack_top);
li_lua_restore_globals(L);

@ -1,6 +1,10 @@
#include <lighttpd/base.h>
#include <lighttpd/config_parser.h>
#ifdef HAVE_LUA_H
# include <lighttpd/config_lua.h>
#endif
#if 0
#define _printf(fmt, ...) g_print(fmt, __VA_ARGS__)
#else
@ -707,6 +711,31 @@
li_value_free(val);
}
#ifdef HAVE_LUA_H
else if (g_str_equal(name->data.string->str, "include_lua")) {
if (val->type != LI_VALUE_STRING) {
WARNING(srv, "include_lua directive takes a string as parameter, %s given", li_value_type_string(val->type));
li_value_free(name);
li_value_free(val);
return FALSE;
}
if (!li_config_lua_load(srv, val->data.string->str, &a)) {
ERROR(srv, "include_lua '%s' failed", val->data.string->str);
li_value_free(name);
li_value_free(val);
return FALSE;
}
li_value_free(name);
li_value_free(val);
/* include lua doesn't need to produce an action */
if (a != NULL) {
al = g_queue_peek_head(ctx->action_list_stack);
g_array_append_val(al->data.list, a);
}
}
#endif
/* internal functions */
else if (g_str_has_prefix(name->data.string->str, "__")) {
if (g_str_equal(name->data.string->str + 2, "print")) {

@ -131,7 +131,7 @@ int main(int argc, char *argv[]) {
}
else {
#ifdef HAVE_LUA_H
li_config_lua_load(srv, config_path);
li_config_lua_load(srv, config_path, &srv->mainaction);
/* lua config frontend */
#else
g_print("lua config frontend not available\n");

Loading…
Cancel
Save