[Prev][Next][Index][Thread]
Re: a table of c funtion pointers
Because of some other issues, I ended up having to resort to write some C
glue
code. The C glue code is fairly small and entirely platform independent (no
Win32 specific calls). In any case, I've successfully started a Java VM and
called some methods. I do have one additional problem: there is a <C-long>
class, however, it is the same size as <machine-word>, whereas Java long is
64 bit. Hmm ... any clean solutions besides resorting to my C glue code
again?
Another question I have, because of my limited few days of experience with
Dylan,
is that how does it support delegation and dynamic compiling. In Smalltalk
or
Objective-C, when a method is not understood by an object, the object is
given the chance to handle it by implementing the doesNotUnderstand: method.
This is very useful when designing a generic proxy server system. To do
the same thing in Java, one can use the dynamic proxy interfaces newly
introduced in JDK 1.3. How does Dylan permit this behavior? Second, in
Java, I can generate source code at runtime, then invoke an external process
to compile the code and finally load the resulting class file using a
ClassLoader,
all during while the application is running. In Smalltalk, one can use the
Compiler class to compile source code at runtime and have the new behavior
while the application is running. How does Dylan accomplishes this given
that
everything is compiled to an exe and that I am not aware of a platform
independent
bytecode representation?
Rob Myers wrote:
> 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: