diff --git a/src/main.c b/src/main.c index 2611272b..7fe90873 100644 --- a/src/main.c +++ b/src/main.c @@ -557,9 +557,9 @@ static void set_absolute_path(char *options[], const char *option_name, #ifdef USE_LUA #define main luatest_main -#define luaL_openlibs lua_civet_openlibs +#define luaL_openlibs lua_civet_open_all_libs struct lua_State; -extern void lua_civet_openlibs(struct lua_State *L); +extern void lua_civet_open_all_libs(struct lua_State *L); #include "../src/third_party/lua-5.2.3/src/lua.c" #undef main #endif diff --git a/src/mod_lua.inl b/src/mod_lua.inl index 945ddbc6..0620652e 100644 --- a/src/mod_lua.inl +++ b/src/mod_lua.inl @@ -982,12 +982,12 @@ static void prepare_lua_request_info(struct mg_connection *conn, lua_State *L) lua_rawset(L, -3); } -static void prepare_lua_environment(struct mg_context * ctx, struct mg_connection *conn, struct lua_websock_data *conn_list, lua_State *L, const char *script_name, int lua_env_type) +void lua_civet_open_all_libs(lua_State *L) { - extern void luaL_openlibs(lua_State *); - luaL_openlibs(L); - - assert(ctx); + { + extern void luaL_openlibs(lua_State *); + luaL_openlibs(L); + } #ifdef USE_LUA_SQLITE3 { @@ -1007,6 +1007,11 @@ static void prepare_lua_environment(struct mg_context * ctx, struct mg_connectio luaopen_lfs(L); } #endif +} + +static void prepare_lua_environment(struct mg_context * ctx, struct mg_connection *conn, struct lua_websock_data *conn_list, lua_State *L, const char *script_name, int lua_env_type) +{ + lua_civet_open_all_libs(L); luaL_newmetatable(L, LUASOCKET); lua_pushliteral(L, "__index"); @@ -1108,12 +1113,6 @@ static void prepare_lua_environment(struct mg_context * ctx, struct mg_connectio } } -void lua_civet_openlibs(lua_State *L) -{ - static struct mg_context fake_ctx; - prepare_lua_environment(&fake_ctx, NULL, NULL, L, NULL, 0); -} - static int lua_error_handler(lua_State *L) { const char *error_msg = lua_isstring(L, -1) ? lua_tostring(L, -1) : "?\n";