-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev091 增加自載機制 #158
Dev091 增加自載機制 #158
Conversation
Signed-off-by: Shewer Lu <[email protected]>
Signed-off-by: Shewer Lu <[email protected]>
Signed-off-by: Shewer Lu <[email protected]>
Signed-off-by: Shewer Lu <[email protected]>
假若想加载的是 |
<userdata_dir>/lua/sample/lua/charset.lua slash_char= package.config:sub(1,1)
package.path =package.path .. ("./lua/sample/lua/?.lua" ):gsub("/",slash_char) )
|
不是指 path 的问题。是指 |
這是兩個 lua_filter ,在 lua_filter@xxxx@xxxx raw_init() 載入兩個 -- charset.lua
...
...
_G["comment_filter"] = _G["comment_filter"] or comment_filter
return filter .custom.yaml patch:
engine/filters/+:
- lua_filter@cherset
- lua_filter@comment_filter |
不太能接受这种取巧的方法,因此目前看来自载功能只能适用于一些特殊情况(require 恰好返回一个 lua component)。 如果我们还是想要这个功能,不如与 还有一个问题:自载是否修改全局空间?如修改它与 |
|不太能接受这种取巧的方法,因此目前看来自载功能只能适用于一些特殊情况(require 恰好返回一个 lua component)。 不大明白 你的意思, 我是按 librime-lua架構 自載只有一個目的 ,把 module 掛上 _G 狀況一 下面 m1 和 m2 指向同一個 module1 內的 functions(init, func,fini)或 func 如同 alias 意義不大 狀況二 下面不應該發生,應該避免, 掛上_G的module 不可再覆蓋可用 m3= m3 or require(m3) m3=m3 or require(m4) 來避免 m3= require 'module3' 以我的反查filter 用的是 mfilter 差異化的變數 來自 name_space/....., 和 env | 还有一个问题:自载是否修改全局空间?如修改它与 rime.lua 全局变量的修改的先后顺序是什么? |
是我没表达清楚,对自载我总体上没意见,只是不能接受如下 “主副模組” 的自载方法:
我希望能保留不自载的行为,用于手工处理像
如果在 |
| 如果在 rime.lua 定义了与模组相同的变量,那么最终被使用的是哪一个? raw_init 中 只有 在 rime.lua 沒有載入時,如果rime.lua定義了 lua_getglobal(L, t.klass.c_str());
if (lua_type(L, -1) == LUA_TNIL){
/*
if _G[klass] == nil then
_G[klass] = require (klass)
lua_getglobal(L, t.klass.c_str()); // 再次放入 stack
end
*/
//---- 回到正常程序 -----
//.... |
試用幾天 ,感覺良好 。在.custom.yaml 加上 component |
即使有多個 component user 還是要在rime.lua 調用到 _G 程序 Line 76 in 7bbf79d
以上例製作多模組必要patch 兩個檔 rime.lua & custom.yaml 才能運作 如果其他user誤用發生時機是在 custom.yaml 用上lua_component@charset ,且沒有在rime.lua 設定_G["charset"]時, 但是最終是失敗的因爲 不符 component initialize 需求( func or [func , init , fini] 我覺得 auto_lua_filter 也是只能載入一個自身一個 在engine.cc裡 我在自己的專案中 是利用 lua_processor@init_proc 在processor init 時 |
the other way , can you accept that? --charset.lua
return { filter = charset_filter,
comment_filter = charset_comment_filter } change to yaml |
重新回顾了一下。还是希望能在保留原来不自动加载的前提下,扩展自动加载。 比如之前提议的 分开两种模式(自动与非自动),行为上更加清楚和确定。比如不会因为
在新增的自动模式里面,接受。 |
auto_lua_xxx 應該是可以用在主動載入 file , 但是要放在 local table or function
不管是auto_lua_xxx and lua_xxx, module name
自載井非主動 覆蓋載入 ,而是 engine 建構lua_xxx 時找不到 _G[module] 時 觸發救援機制 嘗試 require '' -> _G[module] require 'charset.lua' user 在 engine/filters: 且未在rime.lua 淮備好
此兩個會載入失敗 救援自載機制也會失敗, |
現在在lua_xxxx 找不到 _G[module] : type table or function 目前我使用 lua script 也井非主動自載 , 而是在 lua_processor init 時 取得 engine.schema.config 時檢查以下 剩餘 lua_xxxx@module_name@xxx, _G[module_name] 是否空值 , 嘗試用 module_name 載入( require , check type , 掛入_G[module_name] ) |
已由 #189 实现。 |
lua script
<userdata_dir>/lua/date.lua
.custom.yaml
patch:
engine/translators/lua_translator@date