Friday, December 25, 2009

Yabasic and modules

I have not posted here for a little while—as I noted in my last post, I have been on holiday in New Zealand. I am sorry to say that this post will be rather short, as well. But before I start, I'd like to welcome Pedro Sá to the Yabasic blog: he is currently working on implementing modules (or "plugins", if you prefer that terminology) for Yabasic; and he now has posting access here, so I'm looking forward to hearing directly from him about his work so far.

Currently, the modules system works as follows: (1) C functions are imported into Yabasic, using the new csub statement, by a Yabasic library which provides a Yabasic interface to a module; (2) the user imports the library (using use or import); and (3) the user is able to run the C functions in the module through the library interface.

Let's have a look at how that might work in practice.

An extract from the (yet-to-be-created) library sdl.yab might look something like the following:

csub openwindow (x, y, name$) from "sdl"
csub usewindow (window_id) from "sdl"
csub updatewindow () from "sdl"
csub closewindow () from "sdl"
csub color (red, green, blue) from "sdl"
csub circle (x, y, radius) from "sdl"
csub readkey$ () from "sdl"

Then a user might write a program, circle.yab, which looked something like the following:

use "sdl" as "gui"

gui.usewindow (gui.openwindow (100, 100, "Circle"))
gui.color (0, 0, 0)
gui.circle (50, 50, 20)
gui.updatewindow ()
gui.readkey$ ()
gui.closewindow ()

That's a very tentative example, because a lot of development work is currently taking place, so don't start writing your module-using programs just yet!

There have been a few minor hiccups so far, but Pedro has done a good job addressing these issues. Many others have helped out in this process, and I would like to personally express my appreciation to them.

And we would love to hear your suggestions and feedback on modules, because nothing is yet written in stone...

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.