Sorry, I still don't get it entirely. The code now looks like this (in 
simplified form) with a callable object Obj defined in the module:

macro CALL_VARARG(obj,args...)
    quote
        f = handler_function($(esc(obj)))
        ccall(f,Obj,$(Expr(:tuple,[Obj for arg in 1:nargs]...)),$([esc(arg) 
for arg in args]...))
    end
end

(obj::Obj)(args...) = @CALL_nARGS(obj,map(Obj,args)...)

and given x a function object taking one argument and xx a function object 
taking 2 arguments, and y an object,

julia> GAP.@CALL_nARGS(x,y) # all fine
<obj 1>

julia> x(y) # same answer
<obj 1>

julia> GAP.@CALL_nARGS(xx,y,y) # all fine
<obj 2>

julia> xx(y,y) # oops!
ERROR: MethodError: no method matching cconvert(::Type{GAP.Obj}, ::GAP.Obj, 
::GAP.Obj)

So the splicing $(args...) you wrote is necessary for pass the correct 
arguments to ccall, but the cconvert method gets applied to "args..." and 
not individually to all elements of args.

Strangely enough, cconvert is not documented in Julia (?cconvert returns 
nothing) even though it's on the online docs; and no method seems available 
(methods(cconvert) returns nothing).

Thanks in advance! Laurent

Reply via email to