Re: How to pass a Java callable to C#?

Doug Blank <[email protected]>
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <CAAusYChHfOC8Ba9wxMsve-K-+5NP2bnn+=2FeF+jGbQ1TrSp-g@mail.gmail.com>
Jeroen,

Thanks for the feedback, but I think I didn't explain very well my problem.
The Widget library is written in C# and is being used by the Java
interpreter (running on the CLR). I wish to be able to register the
callback in Java.

This works in IronPython, because IronPython knows how to map Python
functions onto Func<object,object>:

"""
from Widgets import Widget
def f(obj):
    print("Click!")
w = Widget()
w.on_click(f)
"""

I have the same working in a Scheme running on the CLR, because I can
define and wrap around callback1 in C#  to map it to Func<object,object>:

"""
(using "Widgets")
(define f (lambda (obj) (printf "~a\n" obj))
(define w (Widget))
(w.on_click (callback1 f))
"""

So, I'm trying to figure out how to do the same thing in Java: map
something in Java onto Func<object,object>, so something like this will
work in DynamicJava:

"""
import static cli.Widgets.*;

public int f(Object widget) {
}

Widget w = new Widget();
w.on_click(f);
"""

Does ikvm have something built-in to help pass a Java function to C#? Or do
you have a general strategy for doing this?

Thanks for any further hints,

-Doug


On Sun, Feb 16, 2014 at 4:21 AM, Jeroen Frijters <[email protected]> wrote:

> Hi Doug,
>
> I'm probably misunderstanding the question, but in Java you'd use
> interfaces for this. See
> http://docs.oracle.com/javase/7/docs/api/java/awt/Button.html#addActionListener(java.awt.event.ActionListener)for example.
>
> Regards,
> Jeroen
>
> > -----Original Message-----
> > From: Doug Blank [mailto:[email protected]]
> > Sent: Sunday, February 16, 2014 0:57
> > To: [email protected]
> > Subject: [Ikvm-developers] How to pass a Java callable to C#?
> >
> > I am doing some refining on the DynamicJava interpreter written in Java
> > that is running under Mono [1]. (C# libraries are made available to the
> > interpreted Java through ikvmstub, and the Java interpreter is running
> > by being compiled with ikvmc). Everything is working very well, but one
> > thing I would like to do is be able to pass a Java callback to a C#
> > function.
> >
> >
> > The C# code looks like this (although I could change it in any manner):
> >
> >
> > public class Widget {
> > public void on_click(System.Func<object,object> function) {
> >         }
> > }
> >
> > In general, how would a Java program register a callback to the C#? I
> > can write an interface on either the Java side, or the C# side.
> >
> > Thanks for any suggestions,
> >
> > -Doug
> >
> > [1] -
> > https://bitbucket.org/ipre/calico/src/master/languages/Java/dynamicjava/
>

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk

_______________________________________________
Ikvm-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ikvm-developers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.