[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Let's talk about __call
- From: Patrick Donnelly <batrick@...>
- Date: Thu, 21 Jul 2016 22:57:26 -0400
For some slightly early "It's Friday" discussion, what do you use the
__call metamethod for? Discuss your favorite hacks, strange problems
solved, code golf hole-in-ones, etc.
To get discussion started, I'll leave this here:
t = setmetatable({}, {__index = table, __call = function(t, method)
return function(...) t[method](t, ...) end end}) -- create a method
binding
string.gsub("foo", ".", t "insert")
for k,v in pairs(t) do print(k,v) end --> 1 f \n 2 o \n 3 o \n
--
Patrick Donnelly