[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Table init syntax suggestion
- From: lhf@... (Luiz Henrique de Figueiredo)
- Date: Mon, 26 Oct 1998 17:10:23 -0200 (EDT)
>From: David Jeske <jeske@home.chat.net>
>
>It occured to me that it would be really neat to be able to setup
>fallback methods 'inline' in table creation.
>
>For example, instead of doing:
>
>a_tag = newtag();
>settagmethod("gc",function () print("resource closed"); end);
>a_table = { [1] = "foo",
> [2] = "bar" };
>settag(a_table,a_tag);
>
>It would be convinent to do:
>
>a_table = { [1] = "foo",
> [2] = "bar",
> [`gc] = function () print("resource closed"); end };
>
>Or something along those lines.
how about this:
function T(a)
local a_tag = newtag();
if a._gc then settagmethod(a_tag,"gc",a._gc) end
settag(a,a_tag)
return a
end
a_table = T{ [1] = "foo",
[2] = "bar",
_gc = function () print("resource closed"); end };
--lhf