From fa4738e86565ae5bc91a8b6725b3b6ece3a0010e Mon Sep 17 00:00:00 2001 From: ivanr Date: Thu, 20 Dec 2007 09:21:35 +0000 Subject: [PATCH] Lua: Preserve entire scripts, not just main(). This allows for more complex logic to be written as the user can now use functions. It also allows room for future expansion. --- apache2/msc_lua.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apache2/msc_lua.c b/apache2/msc_lua.c index 0346fff1..06f6a1cd 100644 --- a/apache2/msc_lua.c +++ b/apache2/msc_lua.c @@ -84,10 +84,10 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) { } /* Compile script. */ - lua_pcall(L, 0, 0, 0); + // lua_pcall(L, 0, 0, 0); /* Find the execution entry point. */ - lua_getglobal(L, "main"); + // lua_getglobal(L, "main"); /* Dump the script into binary form. */ dump.pool = pool; @@ -264,7 +264,12 @@ int lua_execute(msre_rule *rule, modsec_rec *msr, char **error_msg) { return -1; } - /* Execute script. */ + /* Execute the chunk so that the functions are defined. */ + lua_pcall(L, 0, 0, 0); + + /* Execute main() */ + lua_getglobal(L, "main"); + if (lua_pcall(L, 0, 1, 0)) { *error_msg = apr_psprintf(msr->mp, "Lua: Script execution failed: %s", lua_tostring(L, -1)); return -1;