Programming

When Android doesn’t Launch your application

As I've been getting started with Android I decided to take some notes. What follows is something I wrote down as I was working on getting a first sample to build and download from Eclipse using ADT. I followed the instructions from Google and tried the troubleshooting directions. My platform is OpenSuse 10.3 Linux. This note might be helpful if you're trying to develop for Android.

Catching Errors when your Lua Script doesn’t start

Getting an error code back when a Lua script dies is actually pretty straightforward. Use lua_pcall() or one of its relatives to call the script and the return value will tell if there's been a run time error.

The Hilbert Curve in Java, Lua and C++

I wrote a program a little while ago that draws a Hilbert Curve. Really all I did was adapt the Java source code that’s on the Wikipedia page talking about the curve. That Java source used a class called SimpleGraphics that I’m not familiar with. I wanted to use SDL in C++ for my program. It was easy enough to convert the Java code to C++ but to do the drawing I decided to just implement a SimpleGraphics class in C++ that uses SDL to perform the actions that the program needs.

Since then I revived my interest in integrating scripting with C++ and pulled a Lua interpreter in to that project. Now my program loads a Lua script and executes it. The Lua script has access to the SimpleGraphics class that I wrote. Now that the script interpreter works and can call the drawing methods I decided to take the algorithm for drawing the Hilbert curve and implement that as a Lua script. It was actually pretty easy. The resulting source code works as a sort of Rosetta stone for the three languages.

A Quick Run at Google’s Android

I took a little break today from the C++ and Lua stuff I've been doing to have a look at Google's new phone platform. I followed the installation instructions and had some demos up and running pretty quickly. I also grabbed the source and poked around to see whose shoulders they stand on.

Ooops - A SWIG Interface Correction

I glossed over the fact that my program crashed at the end of the script in my post on hooking up Lua to a C++ application. I new at the time I posted that there was a memory problem in calling the SimpleGraphics destructor but what I didn't realize was that the problem was actually caused by the difference in the declaration of the SimpleGraphics class between the header file that the C++ program sees and the declaration that the SWIG-generated file sees. Here's the one that gets compiled in to the C++ application:

Using SWIG to connect C++ to Lua

I closed off my last post about adding Lua to an SDL application saying I’d look at a tool to do the bindings for me. I actually already had something in mind for the job. I looked at a couple but SWIG seems to be the most versatile. It’s not tied just to Lua so the work I put in to learning how to use SWIG will also apply partly to any other scripting languages I want to support. Any within the realm that SWIG supports, of course. Notably missing from the list so far is Javascript. Scheme is represented in the form of Guile (which is a specific Scheme interpreter as far as I understand). The documentation for SWIG is pretty sizable but of course with all the combinations of host & script language out there they aren’t all explained clearly enough for a beginner like me. So I started to experiment. SWIG focuses on wrappers for C, C++ support seems more complex. So to understand things I had to scale back even from my simple SDL C++ test program then scaled back up once I got some communication between code written in both languages.

Starting a Simple Example using Lua and SDL in C++

I’ve been poking around with a couple C++ programs recently and I started thinking again about how cool it is that you can hook in a scripting language. I’ve wanted to try setting up scripting for a few programs in the past but it always seems too far removed from any one project. This sounds kind of abstract, more concretely I’ve been thinking about scripting behaviours in a game or exposing a script interface from some simple graphics program.

Lua’s a popular scripting language for games. It’s used for add-ons in World of Warcraft and I’ve heard it brought up over and over again at the Game Developer’s Conference. I tried a short example of Lua a while back but I never went back to write any real code with Lua. Since the license is so liberal and writing a little Lua would help me out writing WoW macros and add-ons, I decided Lua would be a good place to start - have a look at yesterday's post about setting up an SDL project in Visual Studio.

Next for the test harness. I took some code to draw a Hilbert curve from Wikipedia about a week ago and converted it into something roughly equivalent in C++ using SDL. The code compiles and runs under Linux (I used KDevelop) or Visual Studio 2003. In the code I implemented a SimpleGraphics class which takes an SDL surface and gives some methods to draw lines on that surface. The HilbertCurve class uses a SimpleGraphics object to do the drawing. I decided this little program would be a great candidate to get scripted.

My first run-in with Managed Code

I've heard complaints about dealing with managed code and headaches dealing with mixing managed and unmanaged code but for the most part these problems have been just bits of conversation to me. Until now. See, the last version of Visual Studio that I used for really intense work was VC6. I still feel that the product's been riding down the crapwave ever since. In the interim most of my work has been in Linux or cross-platform script stuff. I've got a little project that I'm currently trying to get building on Visual Studio 2003. It uses SDL and Lua. Basically I want to build a little test harness, but more on that later. I already had the project building in Linux using just the SDL libraries then I created a project in VS2003 to build the same source. I followed the description from this thread on GameDev.net. The SDL project built and all was well.

Wanted: C++ Standard Template Library Docs

I've decided I need a good reference for the STL. I had the misfortune of getting started with the STL back when Microsoft begrudgingly included it in Visual Studio 6. VS6 was a great product - especially for the time. But there was obviously no love for Standard Template Library. Jeff and I have been working on a game for a while. Nothing big, just a fun side-thing to get us in to coding in C++ on Linux. Thing is, Jeff is streets ahead of me when it comes to STL. These days I'm not in to the generic, programming for programming's sake way. I'm mostly interested in learning through doing though. I don't want to see any tutorials or sample code that shows off how smart the author is. I don't believe in Singletons and I think Functors are the work of the devil. Design patterns are a good idea but are often abused. I need thorough reference material and simple examples that suit normal usage. Any ideas?

Adding the ztdummy Timer Module to an Asterisk 1.2 Server

I've been talking about my plans for configuring Asterisk in my home for a few days now. I said that I want users of the system to be able to access voicemail, dial out and make conference calls. The only one of these features that I haven't at least tried out is conference calling. Conference calls in Asterisk can be set up with an application called MeetMe. When reading up on how to set up a MeetMe conference I saw repeated references to a requirement for a timer module. The reason a timer module is required is that Asterisk needs accurate timing to mix the two voice streams in real time. One method of timing uses special-purpose timer hardware on a PCI card that many Asterisk users have. My Asterisk server has no special hardware yet (though I did order an ATA today - the Linksys PAP2T-NA). The other method of getting a timer to work is by installing the ztdummy module. The module is called ztdummy because it works in lieu of a the real zaptel hardware device. Today I'm sharing my notes on how I installed the ztdummy timer module. The ideas and some commands might be helpful, but keep in mind my situation is with a test server that's got no live calls. Don't blindly copy what I've done if you care much about keeping your server running.
Syndicate content