2023-03-13 11:51:46 +08:00
|
|
|
---Set or Get metatable which will find module in folder
|
|
|
|
---@param folder_name string
|
|
|
|
---@param origin table?
|
|
|
|
---@return table
|
|
|
|
local function metatable(folder_name, origin)
|
|
|
|
return setmetatable(origin or {}, {
|
2023-03-12 11:23:29 +08:00
|
|
|
__index = function(tbl, key)
|
|
|
|
local status, result = pcall(require, ('Trans.%s.%s'):format(folder_name, key))
|
|
|
|
|
|
|
|
if not status then
|
|
|
|
error('fail to load: ' .. key .. '\n' .. result)
|
|
|
|
end
|
|
|
|
|
|
|
|
tbl[key] = result
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
local M = metatable('core')
|
2023-02-03 11:57:42 +08:00
|
|
|
|
2023-03-11 00:24:48 +08:00
|
|
|
|
2023-03-12 11:23:29 +08:00
|
|
|
M.metatable = metatable
|
|
|
|
M.style = metatable("style")
|
|
|
|
M.wrapper = metatable("wrapper")
|
|
|
|
|
|
|
|
M.cache = {}
|
2022-12-17 16:07:27 +08:00
|
|
|
return M
|