I am trying to create an operator '!' that returns the print function. I am getting the following error:
line 15: attempt to call a number value
stack traceback:
t.lua:15: in main chunk
[C]: ?
My code is below:
local opTable = {}
debug.setmetatable(0,{
_call = function(a,op)
return opTable[op](a)
end
})
local function addOp(operator,f)
opTable[operator] = f
end
addOp('!',print)
print((5)'!')
It seems this should work, because techniqe #3 on http://lua-users.org/wiki/CustomOperators uses almost exactly the same method.