Wednesday, December 28, 2011

Lesson 22: A First (Bigger) Project

After a long hiatus, here is the next lesson in the series. Lesson 22 begins a project which will delve deeper into what is involved in developing larger projects in Haiku. In this case, we begin working on a text editor, QuickEdit.

Programming with Haiku, Lesson 22
Lesson 22 Source Code

Wednesday, October 5, 2011

What's in a Name

In case you haven't heard, Mozilla spawned a new project -- a 3d gaming engine for browsers. The name? Gladius. It's part of a general platform called Paladin. Yes, you heard that right. Paladin. I've even contacted the main developer, Alan Kligman. I haven't heard back from him about the name conflict, but I'm less than pleased. Especially in light of this thread on their Google Groups list. Gee, thanks, guys. I *really* don't want to have to rename my 3-year-old IDE because some people over at Mozilla chose the same name. Stay tuned.

Saturday, September 17, 2011

Hot & Cold... Meh

Yeesh. A month since my last post here. It would seem that sometimes I run hot and cold in my Haiku hacking efforts and right now I seem to have hit a cold spell. I'm just having a hard time conjuring up the motivation to write code, lessons, or much of anything else at the moment. I've started up my own PC repair business on the side from school, so some of my "free" time is being spent working on it. I'm not going anywhere, but apparently I need a little time off. I'm not going anywhere, but things might be quiet for a little while. You know where to find me in the mean time. Have a great one everyone. :-)

Wednesday, August 17, 2011

Time Flies...

Even when you're not having fun, it seems. I haven't been doing anything out of the ordinary and, lo and behold, it's the first day of school for me. Time seems to have gotten away from me on this one -- I haven't been able to get done anything I planned to a couple of weeks ago. It'll probably take a little time to recover from the madness that is the schedule during the first couple of weeks of school, but I haven't given up. I've got a lesson that is almost complete and ready to publish and another started. Paladin is making good headway but I apparently won't get a release out before summer's end. Ah well. C'est la vie. Until next time, everyone.

Monday, August 1, 2011

News Stew

From the looks of this blog the last few weeks, you'd think that I'd dropped off the face of the earth, but you'd be wrong. I've just been too busy to post. I took a week off for vacation, but I've also been coding quite a bit. I planned on doing a lot more while on vacation -- coding is fun for me -- but I ran into some problems which shot most of the time I could've spent writing code. Anyway, I'm in the process of retooling the code responsible for using project templates in order to make them more flexible. I've also been working on a couple of lessons. One finishes out the Translation Kit, but it's taking a *lot* longer than most lessons would because I'm in the process of learning the basics of writing a Translator and a support framework for writing them. Writing a Translator isn't hard, but it is unfamiliar for me.

Paladin's next release is now on the horizon. The new work on the template section will make more complicated possible, including one which is *this* *close* to being usable: a Tracker Addon template which should make writing them dramatically easier. There are some new command-line utilities which I've written that should come in handy. luare (lu-AR-ay), does regular expression search-and-replace without the mess that is sed. luagrep searches for text in a file, but only one file -- it's mostly meant to be used in combination with find. A text-based build system, pbuild, should make into the release. I've wanted to use a text-based build system for Paladin development, but I wasn't satisfied by any of them out there: make is weird and aggravating, scons is slow, jam has zero documentation, and many are just overkill. pbuild leverages full-blown Lua in a way that you don't have to write much to do basic tasks, but more complicated stuff is possible.

New to Paladin is a Find command which searches all project files and it works quite nicely. It'll be possible to search using regular expressions, but it will be using Lua's regular expressions. Lua doesn't do regular expressions quite the same as Perl or *NIX, but it's pretty close -- most of the differences are just few obscure uses. The boost in speed and simplicity are worth the change.

I haven't stopped writing, just slowed down because the work isn't as easy or fast as I'd like and I'm also trying to get most of the Paladin work for the release done before I have to go back to school. Have a great one, everybody!

Tuesday, July 5, 2011

Programming with Haiku, Lesson 21: Replicants

Here is a topic that for the longest time as a BeOS/Haiku developer, I had no idea how to do and didn't really feel enthused on the concept of learning. Of course, now all the major platforms have desktop gadgets. Ironically, writing a replicant is really easy if you already know how to write basic Haiku GUI applications already. Find out how in this lesson.

Programming with Haiku, Lesson 21

COOOder Craziness in Ubuntu

Here's a quick tip for all of you who use the package openoffice.org-coooder in Ubuntu: don't install from Synaptic. It won't work unless you know some advanced dpkg kung-fu that I don't. Instead, go to your friendly neighborhood Ubuntu mirror and download the .deb manually. Double-click on it to install it and everything will work just fine. Here's a download link for your convenience: COOOder at the US Ubuntu mirror. Have a great day everyone!

Tuesday, June 14, 2011

Haiku, Meet Lua. Lua, Haiku

I've been pretty quiet since I got out of school last week. It's not because I've been too busy to do anything. Quite the contrary. I've had my head down in the trenches, hacking away. About six months ago, I posted a screenshot of CHaikuRun, a test application which interacted with the Haiku API from the C language. I have a new one:



On the outside, not all that different from the other one. Under the hood, though, the two test apps are worlds apart. Here is the source code:


function LuaAppSetupFunction()
    local win = MakeObject("PWindow");
    win.SetProperty("Frame", PRect(100,100,500,400))
    win.SetProperty("Flags", BQuitOnWindowClose)
    win.SetProperty("Title", "LuaGUI")

    local view = MakeObject("PView")
    view.SetProperty("Frame", PRect(0,0,400,300))
    view.SetProperty("BackColor", PColor(224,224,224));
    win.RunMethod("AddChild", {view.id})
   
    local label = MakeObject("PLabel");
    label.SetProperty("Frame", PRect(10, 10, 350, 60))
    label.SetProperty("Text", "Haiku, meet Lua!");
    view.RunMethod("AddChild", {label.id})
end

RunApp("application/x-vnd.dw-LuaGUI", "LuaAppSetupFunction");


That's pretty darn short, if you ask me. A graphical HelloWorld app can be written in 6 lines of code:

function LuaAppSetupFunction()
    local win = MakeObject("PWindow");
    win.SetProperty("Flags", BQuitOnWindowClose)
    win.SetProperty("Title", "Hello Haiku!")
end

RunApp("application/x-vnd.dw-LuaGUI", "LuaAppSetupFunction");


And I thought writing in C++ was easy. Yeesh. That beats everything I've seen under Haiku/BeOS except yab and quite competitive to something like wxPython. Then again, I could argue that this is a lot clearer than yab, but I digress.

The code snippets I've posted above are why I manually wrote Lua bindings instead of using SWIG. I'm not sure that I could have gotten SWIG to generate them in a way which has at least the same ease-of-use as the C++ API. I've still got a *lot* more testing to do and some more objects to implement before I can do a release, but this is definitely some progress and some good news, too. It's officially a good day now. :)

Thursday, June 2, 2011

Libcharlemagne and Paladin

Just a quick post before I head off to bed. :) While school has been as busy as typical this year, last week and this week (mostly this) have been spent with many moments coding. The results? Project-wide find and replace -- a long-needed feature -- and major progress on libcharlemagne. Most of this library work has actually been spent on writing Lua bindings for libcharlemagne. It's not there yet, but it's getting there.

Originally I was going to use SWIG to do it, but it's hard to have a nice API in a language using a generic wrapper. Some language features just don't wrap very well. On the up side, I found out just how flat-out easy it is to call C from Lua. It's almost scary how easy it is. Current code in writing is to turn tables into libcharlemagne's generic data container and vice versa. Hopefully it won't be *too* long before I can post the source for a Lua script that uses the GUI and make a testing release. TTFN

Tuesday, May 17, 2011

Programming with Haiku, Lesson 20: Drag and Drop

In this lesson we seek to understand the part of the Interface Kit which lets us move things around in Tracker using the mouse. We will examine both ways of transferring information from one program to another, both the simple way and the more flexible (and complicated) method.

Programming with Haiku, Lesson 20

Thursday, April 28, 2011

Ubuntu Natty Narwhal: Epic Fail

I saw it coming, and now I can safely say "I told you so" and so can a lot of other people who were expecting the new Ubuntu release to be unstable. 11.04 was released today to much hoopla from many news sites. Never have I been more disappointed by the stability of a release. Ever. Even Karmic Koala -- with which I had a terrible experience -- wasn't as horrific. I'm not even talking about the speed of the repository servers, which have been bombarded and are, thus slow. It would seem that at least on some machines, system stability rests on the edge of a knife. One of my machines would number among that lot.

I have a secondary machine at home which my children usually use to play games on Windows 7. It also runs the Linux distro flavor-of-the-week. During my vacation time this week I've toyed with Kubuntu 10.10, which was unacceptably slow, and Xubuntu 10.10, which had some notable issues. I was underwhelmed by both.

What has been my experience so far? Not good, I'm afraid. I grabbed a copy of Natty this morning, burned it, and started a clean install. The installer has a few minor annnoyances which have been introduced, such as not being able to type in the mount point for a specified partition. Irritating, but I can live with it. It also allows you to skip downloading certain parts. Seeing that the download speeds weren't as good as I liked, I hit the skip button to pass on downloading updates. My clicking was met with a hung installer. Luckily, I had passed the point where I could reboot without hosing the install, so I hard rebooted the thing, which at this point was my only option.

The first official boot didn't go any better. The GRUB screen was distorted, which didn't bode well. Once Ubuntu started booting, the terminal display was an utter mess and completely unreadable. X started and I was informed that I would have to use the classic desktop. The message was completely expected, but it was accompanied by portions of the screen which needed redrawn -- this would be disturbing to a newbie. Next stop: getting the proprietary Nvidia drivers. Ho-hum. They installed without a hitch (surprisingly), but after rebooting into the new shiny Unity environment I was met with yet another surprise: a totally unresponsive desktop. The only thing that it would do is let me move the pointer. The only session option I had which actually works is the Classic desktop with effects disabled. This is actually a step backward considering that it worked very well under Maverick.

I've heard quite a few good things about 11.04, so it can't all be as terrible as my experience has been. I'm sure in the next couple of weeks a lot of things will shake out. Personally speaking, Natty Narwhal should have been a little less ambitious because this release will not reflect well on Ubuntu as a community or on Canonical. Perhaps Oneiric will be better. It certainly can't do much worse.

Tuesday, April 12, 2011

Lesson 19: Deeper in Application Scripting

When we last looked at application scripting in Haiku, we merely scratched the surface. Using the hey command and the basic concepts behind the Haiku scripting model, we were able manipulate running applications to do our bidding. Now we will delve into the C++ code which can do the same thing with much greater flexibility and even implement scripting support in our own GUI controls.

Programming with Haiku, Lesson 19

Monday, April 11, 2011

More Code and Another Lesson Soon

Yeesh. Almost a month since the last post, but I'm still scratching my head trying to figure out where it went. Workload at school went through the roof until last week, so I think that's what happened. Life will hopefully return to some semblance of abnormal. Lesson 19 is almost ready for publication -- look for it hopefully later this week.

I've also been writing some code, too, when I've had a moment. Paladin received a few fixes and tweaks. For example, adding a file to a repository from within the project window also adds its partner file. Same goes for removing it. The Lua scripts that I've written to automatically generate the code for different objects in libcharlemagne received some significant refactoring and the spec files used to create them are simpler now, too. All of the GUI control objects which were complete before are now generated, fixing at least a couple bugs that I discovered while writing the spec files, probably along with some others that I didn't know about. I'm in the process of implementing a couple of objects which were just skeleton files before. More progress is good. :-)

Tuesday, March 15, 2011

Programming Lesson 18: Application Scripting

After a _long_ hiatus, Lesson #18 is available for your reading pleasure. The topic? Scripting Haiku applications, possibly one of the least understood aspects of the operating system. Learn about hey command, its uses, and even see some of the most English-like bash commands ever. Also see how to make almost any Haiku application answer your beck and call and tinker around the operating system with an updated version of the ScriptWorld demo application, Scripting Explorer.

Programming with Haiku, Lesson 18
Supplemental Source Code: Scripting Explorer

Saturday, March 12, 2011

A New Hat... Actually It's a Fedora

I've had fundamental issues with the last few of Ubuntu releases that I've seen come out of Canonical. Jumping from Jaunty to Karmic was foolish -- not all of the bugs had settled out of it for at least a month after its release. Lucid moved the default location of the window buttons -- it is unwise to muck around with a geek's muscle memory. Maverick doesn't seem quite as stable overall, although I've run into fewer problems with jumping from Lucid than Karmic gave me. It is also completely nonsensical and wrongheaded to change introduce a mode to the Close button for Rhythmbox -- it effectively minimizes to the tray if the close button is pressed while it's playing, but closes the program if it isn't. Stupid, stupid, STUPID.

I've been looking for a new distro as a result. Judging from the GNOME vs Canonical news of late, I must not be entirely without justification to be less than satisfied. I've tried Unity. Didn't like it. I've really wanted to go with a Debian based system, if at all possible, because I know the basics of apt well and I like its speed. I wasn't enthused by OpenSUSE's dog-slow first impressions. I've also experimented with CentOS, but I like something a little more up-to-date, so I'm giving Fedora 14 a go. The last time I did anything significant with it was 11(!) versions ago. Still learning, but so far, the experience has been pretty pleasant. I've always liked Red Hat as a company even if I wasn't necessarily wild about RHEL or Fedora. I may be changing my mind about that one. We'll see. Here's to hoping. :-)

Sunday, March 6, 2011

Automatic for the People

It's amazing how sometimes an idea hits me. It dawned on me this past week that much of the work I've been doing on libcharlemagne is grunt work. The code file for the PTextView text editing object is literally like 1000 lines long, far longer than most files that I write, and a large portion is stuff that is repeated with very little variation. In a matter of a few nights and a massive codefest yesterday, I've got the majority of a Lua code generation script which will automate most of the work for the different GUI controls. This is a good thing -- already I've found more than a couple bugs in a couple files just while reviewing them for work with the script. All that's left is the code for generating an object's methods -- tricky, but it should be doable with some thought. The more I work with Lua, the more I wonder what other tasks it might be useful for. Who knows? Perhaps PDesigner might end up as a visual designer with the ability to embed Lua code or something. Interesting thoughts for a pleasant Sunday night after a relaxing day. :)

Tuesday, February 22, 2011

More Progress on Code Lookup

I finally came upon a term for the new Paladin feature that I've been doing R&D on the last couple of weeks: Code Lookup, which will look up code definitions for enumerated types, methods, and more using a database from header files. I'm getting better at hacking Lua, though I would still call myself a novice. I rewrote the parser using a more structured, less hackish approach, and I've managed to make it work pretty well. Considering that I've never delved into this particular realm of computer science before, I'd say that I did OK. It sits on top of the luasql engine at the moment, which needs some more work. Once I've gotten it working properly under Ubuntu, I'll be migrating the project to Haiku. From there, integrating Code Lookup into PalEdit shouldn't be too difficult. I'm not wild about adding more dependencies, but I can easily see greater use of Lua with the Paladin suite because of its flexibility and ease of integration with C/C++. I can't wait until this gets to the point where I can use it under Haiku.

Thursday, February 17, 2011

Libcharlemagne, Lua, and Haiku

The last couple of weekends I've taken a little time away from writing lessons to find some much-needed refreshment in coding. The target? Lua, oddly enough. I twiddled with it for a while and discovered that as scripting languages go, I have to jump through fewer hoops to get something quick-and-dirty done with Lua than others and the code isn't write-only like Perl.

The first project was a doozy: write a C++ header parser and (later on) dump the parsed C++ information into a SQLite3 database so that I have the hard stuff done for implementing something code completion for Paladin. Code completion has been #1 on my hit list of features for a long time now, but I haven't had a clue where to start to implement it, and ctags sure didn't seem to be a step in the right direction. I've learned enough about Lua to really like it and want to eventually put together an elegant implementation of the Haiku API via libcharlemagne. I haven't gotten to more advanced topics like metatables and such, but I'm pretty sure that the rest will come in time. Once I finish cleaning up PalEdit's internals like I was working on last summer, I can easily see embedding Lua scripting into it for more powerful editing features and plugins.

Monday, January 31, 2011

Lesson 17: Writing a New Control, Part I

Yet another three weeks has gone by and I didn't even notice. Yeesh. Time flies when you're coding, so no big deal. *shrug*

This lesson is one of several which delves into the art of control writing for Haiku -- not just a quick-and-dirty hack on an existing one, but writing a new control which rivals existing ones in quality and features. Learn how controls handle drawing themselves and write a basic color display control.

Programming with Haiku, Lesson 17

Thursday, January 27, 2011

C, Meet the Haiku GUI

It's official: after a couple of hours of furious code, I have written a graphical Haiku application from C,  courtesy of libcharlemagne. No, not C++ and there is none of that fancy application scripting via BMessage and hey, either. The title? CHaikuRun, of course.


With mappings from C++ to C being pretty ugly, the code won't exactly win elegance contests. Also, there may be some C-to-HTML ickiness here, so bear that in mind.

#include "libcharlemagne.h"
#include <stdio.h>

int32_t InitApp(void *pobject, PArgList *foo_in, PArgList *foo_out)
{
    /*    This accomplishes the same kinds of tasks as what would
        normally be done in a BApplication's child class constructor */
    
    void *mainwin = pobject_create("PWindow");
    pdata_set_bool_property(mainwin, "Visible", 0);
    pdata_set_string_property(mainwin, "Title", "CHaikuRun");
    pdata_set_rect_property(mainwin, "Frame", 100, 100, 500, 400);
    pdata_set_bool_property(mainwin, "Visible", 1);
    pdata_set_int_property(mainwin, "Flags", 0x00180000);
    
    /* Here is an example of how to run a method for an object in C*/
    void *backview = pobject_create("PView");
    pdata_set_rect_property(backview, "Frame", 0, 0, 400, 300);
    pdata_set_color_property(backview, "BackColor", 224, 224, 224, 255);
    
    /* These have to exist for running a method, but they can be reused */
    PArgList *in = create_parglist();
    PArgList *out = create_parglist();
    
    /* AddChild requires the object ID of the child view to add */
    add_parg_int64(in, "id", pobject_get_id(backview));
    pobject_run_method(mainwin, "AddChild", in, out);
    
    void *label = pobject_create("PLabel");
    pdata_set_rect_property(label, "Frame", 10, 10, 350, 60);
    pdata_set_string_property(label, "Text", "Hello Haiku from the C language!");
    
    empty_parglist(in);
    add_parg_int64(in, "id", pobject_get_id(label));
    pobject_run_method(backview, "AddChild", in, out);
    
    
    /* Free allocated heap memory */
    destroy_parglist(in);
    destroy_parglist(out);
    
    return B_OK;
}


int
main(void)
{
    /* Start up the object system. Without this, we can't do anything with libcharlemagne */
    pobjectspace_init();
    
    void *papp = pobject_create("PApplication");
    run_app(papp, "application/x-vnd.dw-CHaikuRun", InitApp);
    
    /* Not absolutely necessary here, but it frees all objects allocated by the broker */
    pobjectspace_shutdown();
    
    return 0;
}

Wednesday, January 26, 2011

Closer to Scripting Language Support

In the few weeks since my last post I've been working more on bringing the ability to write graphical Haiku applications to languages outside of C++. PDesigner has seen some refactoring, and now it's a lot lighter -- all of the object system code upon which PDesigner has been built was spun out into its own library, libcharlemagne. I'm working with SWIG in order to be able to generate the necessary bindings for the supported languages.

I've run into a small snag, however: I don't know very much about other languages except for a passing familiarity with Python, and certainly not enough about it to know what I'm doing. Just last night I checked in some code to the repository which, in theory, should make it possible to write a Haiku app from Python, Lua, or just about any other scripting language supported by SWIG. There's also a C interface for those people who want to use it. Documentation will be coming soon.

Once I get it to the point where other people will want to use it, it will be available both with the Paladin suite and as a separate download. If you have a little time to tinker and know something about using SWIG for your favorite non-C++ language, get in touch with me.

Sunday, January 9, 2011

Lesson 16: Fonts

Most people think of fonts as merely a means to an end, but in this lesson we will take a crash course in typography and the very basics of displaying text in Haiku. Also included is a review of the second unit, lessons 6 through 15.

Programming With Haiku , Unit 2 Review
Programming With Haiku, Lesson 16

Monday, January 3, 2011

New Year, Same Old Stuff

In about 15 minutes, I'll be heading off to work. The two weeks vacation that I had for Christmas went really fast. This would probably be the first vacation I've had in a long time that I've felt like I didn't get much done.

The big project I spent time working on was PDesigner's object interface. Just a couple of days ago I managed to implement the rest of the code which makes it possible to incrementally learn the interface for any object -- what each object's methods, properties, and events it has and what each method's arguments are and any values it returns. I guess now it's just a matter of adding more of the Haiku API to it and moving the code out of PDesigner and into a shared library when it's ready for release.

The other project I spent time on was more of my Programming with Haiku series. I've hit a bit of a slow spot in the series because I'm not as familiar with the material that the lessons are covering at the moment. Barring major issues, another lesson should be seeing light of day later this week. Have a happy New Year, everyone!