lua-users home
lua-l archive

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


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))