2
debug.getmetatable("").__index = function (s, i) return s:sub(i, i) end
這:
debug.getmetatable("").__index = _proc_lua_read
不起作用。
debug.getmetatable("").__index = function (s, i) return s:sub(i, i) end
這:
debug.getmetatable("").__index = _proc_lua_read
不起作用。
嘗試
debug.getmetatable("").__index = function (s, i) return string.sub(s,i,i) end
注意,通過重新定義__index
在這樣的字符串,你失去了呼籲字符串的方法的能力:注意代碼如何不叫s:sub
。要獲得更好的解決方案,請參閱http://lua-users.org/lists/lua-l/2007-11/msg00619.html。或者設置__call
代替:
getmetatable("").__call = string.sub