Browse Source

Exported mg_prepare_lua_environment()

Sergey Lyubka 12 năm trước cách đây
mục cha
commit
8c118bf4cc
1 tập tin đã thay đổi với 4 bổ sung2 xóa
  1. 4 2
      mod_lua.c

+ 4 - 2
mod_lua.c

@@ -161,7 +161,7 @@ static void reg_function(struct lua_State *L, const char *name,
   lua_rawset(L, -3);
 }
 
-static void prepare_lua_environment(struct mg_connection *conn, lua_State *L) {
+void mg_prepare_lua_environment(struct mg_connection *conn, lua_State *L) {
   const struct mg_request_info *ri = mg_get_request_info(conn);
   extern void luaL_openlibs(lua_State *);
   int i;
@@ -171,6 +171,8 @@ static void prepare_lua_environment(struct mg_connection *conn, lua_State *L) {
   { extern int luaopen_lsqlite3(lua_State *); luaopen_lsqlite3(L); }
 #endif
 
+  if (conn == NULL) return;
+
   // Register mg module
   lua_newtable(L);
 
@@ -243,7 +245,7 @@ static int handle_lsp_request(struct mg_connection *conn, const char *path,
   } else {
     // We're not sending HTTP headers here, Lua page must do it.
     if (ls == NULL) {
-      prepare_lua_environment(conn, L);
+      mg_prepare_lua_environment(conn, L);
       if (conn->ctx->callbacks.init_lua != NULL) {
         conn->ctx->callbacks.init_lua(conn, L);
       }