【发布时间】:2011-04-16 10:31:41
【问题描述】:
这个:
debug.getmetatable("").__index = function (s, i) return s:sub(i, i) end
还有这个:
debug.getmetatable("").__index = _proc_lua_read
不工作。
【问题讨论】:
标签: string lua operator-overloading
这个:
debug.getmetatable("").__index = function (s, i) return s:sub(i, i) end
还有这个:
debug.getmetatable("").__index = _proc_lua_read
不工作。
【问题讨论】:
标签: string lua operator-overloading
试试
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
【讨论】: