I'm trying to imlement my own length method for strings in Lua. I have successfully overriden len() method for string, but I have no idea how to do this for # operator.
orig_len = string.len
function my_len(s)
print(s)
return orig_len(s)
end
string.len = my_len
abc = 'abc'
If I call:
print(abc:len())
It outputs:
abc
3
But
print(#abc)
Outputs only '3' and that means it called original length function instead of mine. Is there a way to make # call my length function?