lua-users home
lua-l archive

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


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