lua-users home
lua-l archive

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


on 2/25/05 9:45 AM, Mark Hamburg at mhamburg@adobe.com wrote:

> If one redefines OP_SELF, then there probably need to be the following
> additional enhancements since the necessary information may not be readily
> available:
> 
> lua_getmethod( lua_State* L ): A C API extension that takes the top two
> objects on the stack as obj and msg and does the appropriate method lookup.
> 
> bindmethod( obj, msg ): A Lua function that takes an object and a message
> and returns a closure that sends msg to obj with any other parameters passed
> to the closure.
> 
> hasmethod( obj, msg ): A Lua function that tests for the presence of a
> message -- i.e., it tells you whether it would be safe to send the message.

D'oh. I forgot callmethod( obj, msg, ... ). One could define bindmethod as:

    function bindmethod( obj, msg )
        return function( ... )
            return callmethod( obj, msg, ... )
        end
    end

It might still be advantageous to write this in C where the stack
manipulation may be easier or more efficient, but it isn't strictly
required.

Mark