[Larceny-users] Small Victories

David Rush kumoyuki at gmail.com
Thu Apr 19 12:29:36 EDT 2007


Greetings my Larcenous compadres -

Given that I had just about zero motivation for doing anything today,
I have to say that, if nothing else, Common Larceny has provided me
with enough of a reason to live that I'm actually almost but not quite
totally unlike happy :) Because well...I managed to launch an Visual
C# Express-built .NET UI from within Common Larceny - a small victory,
but one that is not well-documented as far as I can tell. So, in the
interest of sharing what is probably obvious I include the code
snippet in the sequel to this message.

However, my purpose in posting is to ask for a clue about accessing
and passing SObjects back to the C# code. I tried the first two
obvious things that came to mind:

1 - adding CommonLarceny.exe to my project as a resource
2 - glomming the source code into my solution

However, neither is really giving me the feeling that I can actually
pass SObjects back from Larceny-land into the C# land. Is there a
straightforward approach that I am missing?

And now, for something completely trival:

; this was stolen from examples/CommonLarceny/event-example-2.sch I think
(define (add-event-handler publisher event-name procedure)
  (clr/%add-event-handler (clr-object/clr-handle publisher)
                          event-name
                          (clr/%foreign-box procedure)))

(enable-dotnet!)

; this was the non-obvious part...it *is* obvious in retrospect
(define r (System.Reflection.Assembly.LoadFrom
           "c:/tools/larceny/csharp/Test1/Test1/bin/Debug/Test.dll"))

; largely pirated from examples/CommonLanceny/ as well...
(define plong (Test.Form1.))
(define plong-button (.button1$# plong))

(add-event-handler plong-button "Click"
 (lambda (sender args)
   (write `(got click from ,sender with ,args))
   (newline)))

; And to get the UI up and running from the Larceny REPL...
(System.Windows.Forms.Application.EnableVisualStyles)
(System.Windows.Forms.Application.Run plong)

; it also appears that there's some thread magic going on - I did not
get another REPL
; prompt until the 'plong' window exited. My gut reaction is that this
is a good thing, but
; my opinion may change...

-- 
Once you label me, you negate me
    - Soren Kierkegaard



More information about the Larceny-users mailing list