Aadvert

stringmod

Feb 11th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.44 KB | None | 0 0
  1. local strmt = getmetatable("a")
  2. if type(strmt.__index) ~= "table" then
  3.     print("String[n]: Unable to load twice; or other stuff has already hooked onto strings.")
  4. else
  5.     local origindex = strmt.__index
  6.     function strmt:__index(k)
  7.         if type(k) == "number" then
  8.             if k > string.len(self) or k < 1 then
  9.                 return nil
  10.             else
  11.                 print("DEBUG: !", self, k)
  12.                 return string.sub(self,k, k)
  13.             end
  14.         end
  15.         return origindex[k]
  16.     end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment