#169703 - Karatorian - Thu Jul 30, 2009 7:43 pm
I'm working on an RPG project (please don't bring up any dead equines please, start an new thread if you must) and I figure any RPG engine worth it's salt needs scripting. I could probably write my own (I've done some small language projects before), but that'd be a lot of work. So I decided to look into using Lua. Figuring that someone had most likely already made a port, I started Googling around for what I could find.
There are a couple of interesting projects out there. There's what looks to be a mature DS port here, and, once apon a time, it seems there was a GBA port there. However, I decided to go with Torlus's project. (Well, at first anyway.)
So I downloaded and played around with it. The supplied ROM images worked fine, but I couldn't recompile it due to some issue with bitrot (my toolchain is a lot newer than the one he used). This only required a few adjustments and then everything was good. So I started to dig a little deeper into the code.
Besides having been (apparently) abandoned once the proof of concept was working, the code wasn't really to my liking. Firstly, he modified the Lua code in a way that wasn't required. I wanted to avoid that if at all possible, so I downloaded the latest Lua sources. I made a few changes to the Makefiles to add a "gba" target (but didn't change any sources, woot) and everything seemed to work great, but there was no way to be sure as it was just a library (the command line tools where of no use, clearly).
So the next task was to get Lua4gba to work by linking to the library rather than it's own custom version. This was a little trickier than I'd hoped it would be. He used his own console implementation (which is fine), but for Lua to work with it required the modified version (not so good). So, being lazy, I simply gutted his console code and used the one from libgba, which worked with the standard Lua right out of the box.
Once all that was working, I started looking at the rest of the code. I didn't really like what I saw. The code was kinda a mess. It was composed of a cut down version of "lua.c" interspersed with bits of GBA specific stuff. Basically, it was a port of the Lua intepreter, which wasn't really what I was after. What I wanted instead was to embed Lua using the normal C API (which seems much cleaner to me). So I pretty much started over.
The only part of the code I ended up keeping was the part that loaded a script from a GBFS. I split it out into a seperate function and wrote a new version of main to call it. I based my code on a couple of Lua embedding tutorials I found. It's probably not as robust as the original (error handling? what's that? =_=), but it's cleaner and much smaller.
My code works basically the same way as Lua4gba does. It loads a script from GBFS (the first file found) and attempts to run it. It's not very useful at the moment, but it could be used as the basis for something bigger.
My plans for this in the long term are a little vauge right now. The next thing I plan to do is make an option to embed just the VM and not the compiler. As tight as resources are on the GBA, the slight inconvience of having to precompile the scripts is definitely worth it. Second up will be looking at the options for number types. Lua defaults to using double precision floating point for all numerical calculations. As the GBA has no FPU, that'll have to change. Luckily, there are some compile options for alternatives, so I can hopefully avoid rolling my own. (Although I might if I decide to optimize division and modulo (likely) or do something crazy like fixed point (possible)).
From that point, I'm not really sure. If someone knows of (or is willing to write) a decent virtual keyboard, it'd be cool to do a full fledged port of the interactive interpreter. (But that's not really my aim.) Mainly, I'm going to focus on what I need for my engine, and as a lot of the design is still up in the air, I can't really say for sure what I'll end up doing.
I suppose that one could couple this with some sort of generic game engine and build a game construction kit thingy out of it. If anyone is interested in such a thing, I'd be willing to help out, but I'm not gonna do anything of the sort solo. Furthermore, it looks the the DS port I mentioned above would be a better starting point for that sort of thing.
Anyhoo, you can grab a source tarball from my website and try it out. Sorry, there's no prebuilt ROM images at the moment, but I'll get some up soon.
Comments, critques, and suggestions welcome. Thanks in advance.
There are a couple of interesting projects out there. There's what looks to be a mature DS port here, and, once apon a time, it seems there was a GBA port there. However, I decided to go with Torlus's project. (Well, at first anyway.)
So I downloaded and played around with it. The supplied ROM images worked fine, but I couldn't recompile it due to some issue with bitrot (my toolchain is a lot newer than the one he used). This only required a few adjustments and then everything was good. So I started to dig a little deeper into the code.
Besides having been (apparently) abandoned once the proof of concept was working, the code wasn't really to my liking. Firstly, he modified the Lua code in a way that wasn't required. I wanted to avoid that if at all possible, so I downloaded the latest Lua sources. I made a few changes to the Makefiles to add a "gba" target (but didn't change any sources, woot) and everything seemed to work great, but there was no way to be sure as it was just a library (the command line tools where of no use, clearly).
So the next task was to get Lua4gba to work by linking to the library rather than it's own custom version. This was a little trickier than I'd hoped it would be. He used his own console implementation (which is fine), but for Lua to work with it required the modified version (not so good). So, being lazy, I simply gutted his console code and used the one from libgba, which worked with the standard Lua right out of the box.
Once all that was working, I started looking at the rest of the code. I didn't really like what I saw. The code was kinda a mess. It was composed of a cut down version of "lua.c" interspersed with bits of GBA specific stuff. Basically, it was a port of the Lua intepreter, which wasn't really what I was after. What I wanted instead was to embed Lua using the normal C API (which seems much cleaner to me). So I pretty much started over.
The only part of the code I ended up keeping was the part that loaded a script from a GBFS. I split it out into a seperate function and wrote a new version of main to call it. I based my code on a couple of Lua embedding tutorials I found. It's probably not as robust as the original (error handling? what's that? =_=), but it's cleaner and much smaller.
My code works basically the same way as Lua4gba does. It loads a script from GBFS (the first file found) and attempts to run it. It's not very useful at the moment, but it could be used as the basis for something bigger.
My plans for this in the long term are a little vauge right now. The next thing I plan to do is make an option to embed just the VM and not the compiler. As tight as resources are on the GBA, the slight inconvience of having to precompile the scripts is definitely worth it. Second up will be looking at the options for number types. Lua defaults to using double precision floating point for all numerical calculations. As the GBA has no FPU, that'll have to change. Luckily, there are some compile options for alternatives, so I can hopefully avoid rolling my own. (Although I might if I decide to optimize division and modulo (likely) or do something crazy like fixed point (possible)).
From that point, I'm not really sure. If someone knows of (or is willing to write) a decent virtual keyboard, it'd be cool to do a full fledged port of the interactive interpreter. (But that's not really my aim.) Mainly, I'm going to focus on what I need for my engine, and as a lot of the design is still up in the air, I can't really say for sure what I'll end up doing.
I suppose that one could couple this with some sort of generic game engine and build a game construction kit thingy out of it. If anyone is interested in such a thing, I'd be willing to help out, but I'm not gonna do anything of the sort solo. Furthermore, it looks the the DS port I mentioned above would be a better starting point for that sort of thing.
Anyhoo, you can grab a source tarball from my website and try it out. Sorry, there's no prebuilt ROM images at the moment, but I'll get some up soon.
Comments, critques, and suggestions welcome. Thanks in advance.