lua-users home
lua-l archive

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


Is there a way I can insert an argument for a function during
the index lookup handler of a table, where this lookup is returning
a function?

I am trying to re-direct a function call from the global index
handler to a userdata handler, based on a currently 'active'
object.  The intention being that I can create a kind of 'using'
directive :

obj:FuncA(...)
obj:FuncB(...)
obj:FuncC(...)

with:

UsingObj(obj)
FuncA(...)
FuncB(...)
FuncC(...)


I have successfully set up the handler tables such that the global
handler queries the active 'obj', and it will return FuncA (or whatever)
as required.  However, I cannot find a way to simulate the ':', which
magically inserts obj as the first argument... I have tried pushing
multiple values on to the stack from my handler, but it doesn't seem
to help.

The table lookups and obj functions are all implemented in C, called
with lua_pushcclosure(). Also, to complicate matters slightly, the
available functions are determined at run-time, during index lookup;
I cannot simply define a set of global functions with the same names
and have them call the function off 'obj', as I do not know all the
functions that will be available until the call itself determines this.

Love, Light and Peace,
- Peter Loveday
eyeon Software


----- Original Message ----- 
From: "Edgar Toernig" <froese@gmx.de>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Saturday, December 22, 2001 9:12 PM
Subject: Re: rawget Segmentation Fault


> Roberto Ierusalimschy wrote:
> > 
> > lbaselib.c: 168: function luaB_rawget
> > - lua_rawget(L, -2);
> > + lua_rawget(L, 1);
> > 
> > lbaselib.c: 172: function luaB_rawset
> > - lua_rawset(L, -3);
> > + lua_rawset(L, 1);
> 
> IMHO the right fix would be:
> 
> lbaselib.c: 168: function luaB_rawget
> + lua_settop(L, 2);
>   lua_rawget(L, -2);
> 
> lbaselib.c: 172: function luaB_rawset
> + lua_settop(L, 3);
>   lua_rawset(L, -3);
> 
> Ciao, ET.
>