| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| return function(env) |
| local mod |
| if env == true then |
| mod = {} |
| env = {} |
| end |
| local env = env or {} |
|
|
| local modules = { |
| utils = true,path=true,dir=true,tablex=true,stringio=true,sip=true, |
| input=true,seq=true,lexer=true,stringx=true, |
| config=true,pretty=true,data=true,func=true,text=true, |
| operator=true,lapp=true,array2d=true, |
| comprehension=true,xml=true,types=true, |
| test = true, app = true, file = true, class = true, List = true, |
| Map = true, Set = true, OrderedMap = true, MultiMap = true, |
| Date = true, |
| |
| } |
| rawset(env,'utils',require 'pl.utils') |
|
|
| for name,klass in pairs(env.utils.stdmt) do |
| klass.__index = function(t,key) |
| return require ('pl.'..name)[key] |
| end; |
| end |
|
|
| |
| |
| |
|
|
| local _hook,_prev_index |
| local gmt = {} |
| local prevenvmt = getmetatable(env) |
| if prevenvmt then |
| _prev_index = prevenvmt.__index |
| if prevenvmt.__newindex then |
| gmt.__index = prevenvmt.__newindex |
| end |
| end |
|
|
| function gmt.hook(handler) |
| _hook = handler |
| end |
|
|
| function gmt.__index(t,name) |
| local found = modules[name] |
| |
| |
| if found then |
| |
| rawset(env,name,require('pl.'..name)) |
| return env[name] |
| else |
| local res |
| if _hook then |
| res = _hook(t,name) |
| if res then return res end |
| end |
| if _prev_index then |
| return _prev_index(t,name) |
| end |
| end |
| end |
|
|
| if mod then |
| function gmt.__newindex(t,name,value) |
| mod[name] = value |
| rawset(t,name,value) |
| end |
| end |
|
|
| setmetatable(env,gmt) |
|
|
| return env,mod or env |
| end |
|
|