Browse Source

mg.send_file for Lua

bel 11 years ago
parent
commit
1af0a35aa9
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/mod_lua.inl

+ 12 - 0
src/mod_lua.inl

@@ -333,6 +333,16 @@ static int lsp_redirect(lua_State *L)
     return 0;
 }
 
+/* mg.send_file */
+static int lsp_send_file(lua_State *L)
+{
+    struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
+    const char * filename = lua_tostring(L, -1);
+    mg_send_file(conn, filename);
+    return 0;
+}
+
+/* mg.write for websockets */
 static int lwebsock_write(lua_State *L)
 {
 #ifdef USE_WEBSOCKET
@@ -441,6 +451,8 @@ static void prepare_lua_environment(struct mg_connection *conn, lua_State *L, co
         reg_function(L, "write", lwebsock_write, conn);
     }
 
+    reg_function(L, "send_file", lsp_send_file, conn);
+
     reg_string(L, "version", CIVETWEB_VERSION);
     reg_string(L, "document_root", conn->ctx->config[DOCUMENT_ROOT]);
     reg_string(L, "auth_domain", conn->ctx->config[AUTHENTICATION_DOMAIN]);