[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 9 Dec 2014 20:05:19 +0200
2014-12-09 19:43 GMT+02:00 Thiago L. <fakedme@gmail.com>:
>
> On 09/12/14 03:46 AM, Dirk Laurie wrote:
>>
>> 2014-12-08 21:48 GMT+02:00 Thiago L. <fakedme@gmail.com>:
>>>
>>> On 08/12/14 05:47 PM, Thiago L. wrote:
>>>>
>>>>
>>>> On 08/12/14 02:15 PM, Dirk Laurie wrote:
>>>>>
>>>>> Do you expect the relationship
>>>>> `_ENV.string == getmetatable"".__index`
>>>>> to survive?
>>>>>
>>>> local _ENV = {string = {}}
>>>> print(_ENV.string == getmetatable"".__index) --> false
>>>>
>>> Wait actually I'm not sure what you're asking...?
>>
>> Do you want string.sub(str,i,j) and str:sub(i,j) to do the
>> same (as it now does) after you have assigned something
>> to _META.string?
>>
> I want to be able to tweak it as needed (aka if I change the string table I
> wanna be able to change the string metatable to do the same as the string
> table _BUT_ only inside the sandboxed environment)
>
> So technically, considering I can _ENV.string = {}, it doesn't actually do
> the same does it?
Since string is the only type that works this way, maybe just coding it
in plain Lua is readable enough.
_META = getmetatable""
_INDEX = {sub = function(s, i, j) return "nope" end}
s = "test"
print(s:sub(1,2))
do
local string = _INDEX
_META.__index = string
print(s:sub(1,2),string.sub(s,1,2))
end
_META.__index = string
print(s:sub(1,2))
- References:
- local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}, Thiago L.
- Re: local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}, Dirk Laurie
- Re: local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}, Thiago L.
- Re: local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}, Thiago L.
- Re: local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}, Dirk Laurie
- Re: local _META = {string = {__index = function(s, k) if type(k) == "number" then return string.sub(s, k, k) end return string[k] end}}, Thiago L.