This may be faster: getmetatable("").__index = function (s, n) return type (n) == "number" and rawget (string, "sub")(s, n, n) or rawget (string, n) end -- Shmuel