lua-users home
lua-l archive

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


On Sun, May 3, 2015 at 10:04 AM, Sam Putman <atmanistan@gmail.com> wrote:
> something like
>
>
> local my_url = setmetatable("",UrlMeta)
>
> On Sun, May 3, 2015 at 7:03 AM, Sam Putman <atmanistan@gmail.com> wrote:
>>
>>
>>
>> On Sun, May 3, 2015 at 6:53 AM, Nagaev Boris <bnagaev@gmail.com> wrote:
>>>
>>>
>>> Lua uses one metatable for all strings.
>>>
>>
>> Indeed. My desire is to be able to extend particular strings by putting a
>> metatable
>> between the pointer to the interned string and the global string
>> metatable.
>>
>>
>>
>>>
>>> --
>>>
>>>
>>> Best regards,
>>> Boris Nagaev
>>>
>>
>

local url_method = {}
local url_meta = {__index=url_method}
function url(str)
    return setmetatable({str=str}, url_meta)
end

function url_meta:__tostring() return self.str end
function url_meta:__concat(str) return url(self.str .. str) end
function url_method:sub(...) return self.str:sub(...) end
--etc...

local my_url = url "http://www.lua.org";

-- 
Sent from my Game Boy.