[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Proposal] Thread Metatable
- From: Sean Conner <sean@...>
- Date: Tue, 23 Jun 2015 15:31:02 -0400
It was thus said that the Great Soni L. once stated:
> On 23/06/15 03:57 PM, Sean Conner wrote:
> >>>On Tue, Jun 23, 2015 at 2:11 PM, Soni L. <fakedme@gmail.com> wrote:
> >>
> >>__call and co() makes it look like a function call, which may be kinda
> >>confusing. On the other hand OOP syntax co:resume() is more Lua-like, as
> >>strings have it too. You also cannot index functions.
> > Yes you can.
> >
> > function foo(x)
> > return 3 * x + 5
> > end
> >
> > mt =
> > {
> > __index = function(obj,idx)
> > local d = string.dump(obj)
> > return d:sub(idx,idx)
> > end
> > }
> >
> > debug.setmetatable(foo,mt)
>
> Try it without debug.
lua_getglobal(L,"foo");
lua_getglobal(L,"mt");
lua_setmetatable(L,-2);
-spc