Is it possible to overload operators for strings?
snippet in lua

Is it possible to overload operators for strings?

user7631

getmetatable('').__index = function(str,i) return string.sub(str,i,i) end
getmetatable('').__call = function(str,i) return string.upper(str) end
getmetatable('').__unm = function(str,i) return string.reverse(str) end
getmetatable('').__add = function(str,i) return (str .. i) end
getmetatable('').__mul = function(str,i) return string.rep(str, i) end

local str = "test"

print(str[2]) --> "e"
print(str()) --> "TEST"
print(-str) --> "tset"
print(str + "er") --> "tester"
print(str * 2) --> "testtest"