-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadmodule.lua
executable file
·77 lines (70 loc) · 2.45 KB
/
loadmodule.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env lua
--
-- loadmodule.lua
-- Copyright (C) 2021 Shewer Lu <shewer@gmail.com>
--
-- Distributed under terms of the MIT license.
--
-- compnent
-- load(module , targetname,....) -- load compnent table to global
-- -- xxxx.load('english','english1') english1_processor english1_filter ....
-- module module_name : lua/module_name.lua or lua/module_name/init.lua
-- targetname : setup conpnent name for (processor , filter , segmentor , translator )
-- unload(targetname) unload module
-- --- xxx.unload('english1')
-- init lua compnent to global variable
-- create enter_processor in global
-- create enter_filter in global
-- require( 'main_init')("enter",args)
local compnent={}
-- { targetname= unload_func() , ......}
compnent.unload_funcs={}
--print( "shared_dir:", rime_api.shared_dir() )
--print( "user_dir:", rime_api.user_dir() )
--print( "sync_dir:", rime_api.sync_dir() )
function compnent.load(module,targetname,...)
--local function init(module, targetname, ...)
--
local _tab= require(module)(...) -- module lua_init(...)
-- module must return conpment_tables( processor,filter , translator, segmentor)
-- compnent_table ={
local unload_keys={}
-- set compnent_table to global
for key,compnent_tab in pairs( _tab ) do
local compnent= targetname .. "_" .. key --
log.info("create compnent tabe : " .. tostring( compnent) )
_G[ compnent ] = compnent_tab -- load and v or nil
table.insert(unload_keys, compnent )
end
-- insert unload func to table
compnent.unload_funcs[targetname] = function()
for i,unload_key in ipairs(unload_keys) do
_G[ unload_key] = nil
end
end
return
end
-- unload target table : targetname = english english_procssor{func=nil,init=nil,fini=nil} english_processor=nil
--
function compnent.unload(targetname)
local unload_func= compnent.unload_funcs[targetname]
if type(unload_func)== "function" then
unload_func()
end
compnent.unload_funcs[targetname]=nil
end
-- unload all
function compnent.unload_all()
for k,func in pairs(component.unload_funcs) do
compnent.unload(k)
end
end
return compnent
---
--
-- Component = require( "loadmodule")
--
--
--
-- Compnent.load( "muti_reverse","muti_reverse1" ) -- require( module ,
--