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

Re: a table of c funtion pointers



Futeh Kao wrote:
>
> What should be filled in the ??? slot above.  Is it just
> <c-function-pointer> ?
> If so, how would I call the function safely.

Wrap it, either with the slot accessor, or with a method that calls it:

// slot accessor (getter)

define method get-version( interface :: <JNINativeInterface_> )
	// Call the method with the correct parameters
end method;

// method

define method jni-get-version( interface :: <JNINativeInterface_> )
	// Call the method with the correct parameters
end method;

You can make sure the method is used by not exporting the slot name from
the module the interface is declared in. Note that a getter cannot take
parameters, so as a general approach using exported methods is better.

> Second question.  How do I declare a vararg function and use it in
> Dylan.

A C vararg function? I don't know. If there isn't an API for this, you'd
have to build the va_list by hand in a buffer, and call the function as
normal passing the va_list as a <C-void*>.

A Dylan variable argument function is easy, just add a #rest parameter:

define function my-varargs( one :: <string>, two :: <integer>, #rest
rest )
	// "rest" is a sequence of the varargs params within this method
end method my-varargs;

> BTW, has anyone written an interface to create a Java virtual machine
> and invoke
> Java methods within Dylan so that I am not duplicating the effort?

Not that I know of. When you get this working, be sure to publish it. :-)

- Rob.

-- 
Rob Myers - http://www.robmyers.org/   H2G2 - http://www.h2g2.com/
MacOS wonderfulness for The Hitch Hiker's Guide to the Galaxy Game.
"Don't talk to sociologists. Social practice has no sociological 
content." - Art & Language.



Follow-Ups: References: