Posted 12 September 2013 - 11:39 PM
I was dabbling with metatables recently (see API Advanced) and I thought of this for the lolz.
The Code:
What it does:
This API adds a function which makes other functions able to be called in more ways than just using parenthesis, here's an example of how to use it:
It's probably bugged up like crazy, but I doubt too many people will use it anyways :P/>.
The Code:
Spoiler
new = function(func)
return setmetatable({val = func}, {
__call = function(self, ...)
return self.val(unpack(#arg>1 and arg or type(arg[1])=="table" and arg[1] or {arg[1]} or {nil}))
end;
__index = function(self, key)
local t = {key}
self[key] = setmetatable({}, {
__index = function(self2, key2) t[#t+1] = key2 self2[key2] = self2 return self2[key2] end;
__call = function(self2, ...) return self.val(unpack(t)) end;
})
return self[key]
end;
})
end
What it does:
This API adds a function which makes other functions able to be called in more ways than just using parenthesis, here's an example of how to use it:
Spoiler
-- Example
apple = function(...)
for i, v in ipairs(arg) do
print(v)
end
end
apple = <insertwhateveryoucallthisapi>.new(apple)
apple("thing", "otherthing") --> thing otherthing
apple[5][8]["red"]() --> 5 8 red
apple{"string", "str", "lol"} --> string str lol
apple"something" --> something
It's probably bugged up like crazy, but I doubt too many people will use it anyways :P/>.