welcome to kudla.org

(gambas mdi)

mandrake rpm’s
gambas docs
toga fonts

one shots (so far)
my bookmarklets
OOo cd template

linux desktop (2001-2)

old videogames
my music

my daily surf
(more) rss feeds weather

RSS Feed

Microsoft's final Windows 8.1 update is due on 12 August
Google adds more security to its Gmail servers
Silicon Valley, sitcom style

Topic: linux extending gambas using pipes & perl
11:36pm EDT, 10 Jul 2003

One nifty thing about Linux that is exploited nicely in Gambas is the ability to run programs over pipes. Gambas will let you run a program over a pipe and write to it while also receiving its output without any need to fork or block. So, as it turns out, it's pretty easy to wrap a Gambas class around a helper app and add that application's functionality to Gambas. As a proof of concept, I wrote such a class to do simple matching using Perl's regular expressions, threw a quick and dirty form in the project to demonstrate, and I called it "Squiggle".

Why "Squiggle"? Well, a couple of reasons. One, it's a goofy name to reflect the fact that it's about an hour's worth of code and probably has its share of problems. It's slow (if you keep using the same instance of the class over and over, it should be faster because I used the /o switch on the perl regular expression, which means don't recompile the RE every time you run it) and I think we can all agree that doing things like this isn't the optimal way to extend a language. But it does work and provides a prototype for how native Gambas regular expressions could someday work.

The other reason is that a VB and Perl enthusiast I do a lot of work with is always expressing amazement at what you can do with Perl if you can get used to "all those squiggles". I think Gambas needs some squiggles of its own, so here's one now.

If you want to use the class in your own project, and you're using Gambas 0.61 or later, you may be able to do so without having to copy CSquiggle.class into your source tree. Make sure you have perl installed, put squiggle somewhere Gambas expects to see it, put USE "squiggle" at the top of a module or class in which you want to use it, and use the following methods (where varname is a CSquiggle object and arrayname is a String[]):

  • varname = new CSquiggle("your regular expression")
  • arrayname = varname.Match("some text to run through the RE")
I hope to develop an interface to do substitutions as well (which would work similarly to Replace and Subst in Gambas, where it produces a new string, doesn't operate on the existing one) but the above is all there is to the current version.

Speaking of which, here it is.

back to main


copyright 1994-2004 rob kudla