lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> why does [] not apply to strings?

It does, but it does not do what you want. But try this:

 s="lua"
 print(s[2])
 getmetatable("").__index = function (s,i)
	 if type(i)=="number" then
		 return string.sub(s,i,i)
	 else
		 return string[i]
	 end
 end
 print(s[2])

--lhf