Mod Wombat

lua-users home
wiki

ModWombat 是 Apache 範例,容許您撰寫 Lua 網頁。它僅運作於 Apache 2.3+ (計畫於 Apache 2.4 中以 mod_lua 之名釋出 [1]),並有多項選擇可供重複使用 LuaState?,快取已編譯腳本等。

以下是可/應對 mod_wombat 進行的改善想法。這些想法來自 Brian Akins。

// Ability for other modules to call lua without worrying about caching,
// compiling, etc.  i.e. something like:
APR_DECLARE_OPTIONAL_FN(apr_status_t, lua_request_register, (apr_pool_t
*pool, lua_request_t **new, const char *file));
APR_DECLARE_OPTIONAL_FN(apr_status_t, lua_request_run, (request_rec * r,
lua_request_t *run, const char *function, apr_status_t *rc));

理論上,此概略「架構」會由 mod_wombat 內部使用。

-每一個執行緒虛擬機器。http 執行緒針對每個檔案都有專屬的 lua 虛擬機器。

(我們已完成這兩件事^^。Brian M. 擁有我們版本經過大幅修改的 mod_wombat。如有興趣,我可以將其張貼於此)

支援 httpd.conf Lua。亦即,我希望能在組態中執行「簡單」的 lua,而非必須使用個別檔案。

<Lua my_cool_code>
require 'string'
require 'apache2'
function simple_redirect(r)
    if string.match(r.headers_in['User-Agent'], 'mozilla') then
        r.headers_out['Location'] = 'http://somecoolmozillasite.com/stuff'
        return apache2.HTTP_MOVED_TEMPORARILY
    end 
end
</Lua>

<Location /my_ie_only_app>
   LuaHook fixups my_cool_code:simple_redirect
</Location>

(範例不良,但您能理解其概略概念)

能在 Lua 中創造「實際的」範例

function register_hooks(p)
    apache2.hook_handler(my_handler, NULL, NULL, apache2.HOOK_MIDDLE)
end

apache2.module(
    apache2.STANDARD20_MODULE_STUFF,
    create_dir_cfg,
    merge_dir_cfg,
    create_svr_cfg,
    merge_svr_cfg,
    cmd_table,
    register_hooks
)

範例載入是我認為比較棘手的部分。

對於真正有野心的人來說,我希望透過 lua 組態 apache

httpd.load_module('mime_module', 'modules/mod_mime.so')
v = apache2.server.new()
v:document_root = '/opt/apache/htdocs'
mod_mime:types_config = '/etc/mime.types'
mod_env.set_env('X-Lua', 'is cool')

不具效力,但類似這樣的內容...


最近變更 · 喜好設定
編輯 · 歷程
最後編輯時間:2009 年 5 月 18 日,凌晨 1:37 GMT (差異)