[haiku-development] Re: Scripting languages

  • From: Jon Yoder <darkwyrm@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 16 May 2011 20:27:47 -0400

On 05/16/2011 02:19 PM, Donn Cave wrote:
Quoth Ryan Leavengood<leavengood@xxxxxxxxx>,
...
With the recent work of Jon Yoder (aka darkwyrm) on
libcharlemagne[1,2], which may become the "standard" Haiku C API
wrapper, doing the above with Haskell (and other languages for that
matter) may be easier now. In fact maybe you could share some of your
work on a BeOS C API wrapper as it may be useful for Jon for
libcharlemagne.

Interesting.  I have, for both Python and Haskell, tried to apply
the API more directly.  So, for example the window constructor from
the Haskell version of the CHaikuRun program in Jon's blog -

winCx this = do
     view<- withCString "v" $ \ name ->
         cBView Nothing nullBViewDispatch (BRect 0 0 400 300) name [] []
     cBViewSetViewColor view (B_rgb_color 224 224 224 255)
     label<- withCString "just any name" $ \ name ->
         withCString "Hello Haiku from the Haskell language" $ \ text ->
             cBStringView Nothing nullBStringViewDispatch (BRect 10 10 350 60)
                 name text [] [B_WILL_DRAW]
     cBViewAddChild view (fromBStringViewPtr label) nullPtr
     cBWindowAddChild this view nullPtr

cBWindowAddChild is a Haskell library function, that calls
c_BWindowAddChild, that calls HWindow->AddChild - so a couple
of layers, but they're very thin layers that do Haskell-specific
stuff, and I generate them automatically.

The way I see it, the work that can really benefit multiple languages
is the API reference, that can be input to interface generators.
We've corresponded about this here before - similar to interface/Window.h,
but more easily parsed and with extra information as required by more
modern languages.
I've been following this thread pretty closely, what with my already vested interest in bringing the Haiku GUI API to other languages.

I'd say that what the C API should look like really depends on what you want to do. I wanted a generic interface that would make it possible to interact with all of the API using a small set of functions. This would also make it possible to easily add other components to the generic API without having to modify the bindings for each language at all.

Just a quick word of advice: this is a project that is *much* bigger than it looks at first glance. Best of luck to you. :)

--Jon

Other related posts: