这是我用来注册库名称的函数名称注册闭包:
池对象:
function FooBarPool()
local Names = {}
local self = {}
function self:Register(fFoo,sName)
if(fFoo) then
Names[fFoo] = sName
end
end
function self:GetName(fFoo)
return Names[fFoo] or "N/A"
end
return self
end
创建一个池对象
local Pool = FooBarPool()
注册已知的库函数
Pool:Register(string.sub,"string.sub")
Pool:Register(string.gsub,"string.gsub")
Pool:Register(string.match,"string.match")
Pool:Register(string.gmatch,"string.gmatch")
Pool:Register(string.find,"string.find")
Pool:Register(string.gfind,"string.gfind")
Pool:Register(string.format,"string.format")
Pool:Register(string.byte,"string.byte")
Pool:Register(string.char,"string.char")
Pool:Register(string.len,"string.len")
Pool:Register(string.lower,"string.lower")
Pool:Register(string.upper,"string.upper")
Pool:Register(string.rep,"string.rep")
Pool:Register(string.reverse,"string.reverse")
for k,v in pairs(string) do
print(tostring(v) .. " : "..Pool:GetName(v))
end