. , , . , - , , . , NAME_OF_FUNCTION , , , .
, ( _G), , x. , .
a=function() print"fun a" end
b=function() print"fun b" end
t={
a=a,
c=b
}
function NameOfFunctionIn(fun,t)
for k,v in pairs(t) do
if v==fun then return k end
end
end
print(NameOfFunctionIn(a,t))
print(NameOfFunctionIn(b,t))
print(NameOfFunctionIn(b,_G))
, , , :
fun1={
fun=function(self,...)
print("Hello from "..self.name)
print("Arguments received:")
for k,v in pairs{...} do print(k,v) end
end,
name="fun1"
}
fun_mt={
__call=function(t,...)
t.fun(t,...)
end,
__tostring=function(t)
return t.name
end
}
setmetatable(fun1,fun_mt)
fun1('foo')
print(fun1) -- or print(tostring(fun1))
, - . - , , , .. .., . , fun1.fun, , , , .