gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Lua question

#70094 - DakeDesu - Sat Feb 04, 2006 8:48 am

Now, I am not sure how often this question has been asked but it appears that Lua, may be able to be compiled small enough to fit onto one of the larger GBA carts. Now one project I am in the research stages on, uses Lua to make scripting characters simpler, and more game independant.

The idea here is to take Lua, compile it small enough (I don't need all the features it allows) to fit onto a game cartridge, and have the Lua files in a DATA section of the cart memory (seperating it as MVC and Data, as would make perfect sense).

I am sure somebody here has thought of it before me, as I am not really that clever. I am just wondering what sort of stuff that I'd have to look into to make this feasible.
_________________
[ Main Site | Kid Radd Fan Project | Forums ]

#70125 - Quirky - Sat Feb 04, 2006 1:23 pm

It's entirely possible to compile Lua for the GBA. I got the Lua "Life" script running in a 99kb .gba file (94kb was "just lua") using Lua 5.0.2. It isn't especially fast in this example, but I was just experimenting to see what could be done.

I vaguely remember changing a couple of things so as not to include floats anywhere - lua used sprintf instead of siprintf, so I think I added a lua_sprintf macro (I honestly can't remember and looking at the code now doesn't bring much back) there was already a LUA_NUMBER that gets rid of 90% of the float usage and a USE_FLOAT macro too, I think.

I gave up in the end because in order to use Lua properly, I had to write sutiable C wrappers. In doing so I decided that the code I'd written may as well just get called from C anyway and skip the script overhead. The compilation time in suitably modular code is not much greater than using GBFS and appending the scripts, with the added advantage of compile time checking, run time speed, better use of resources, ablilty to debug, etc. "In 1 man projects, the advantages of using a scripting language are probably lessened" was my conclusion.

#70127 - DakeDesu - Sat Feb 04, 2006 1:42 pm

Thanks for the response.

Maybe I should elaborate on my purposes.

The "license" (using the term loosely here) has stated in it throughout a lot of it that rules on the physics and stuff are not based on where they exist, but based upon code in the character.

The only game code that isn't in each object, character and whatnot would be the limits on the code (like say, only being able to charge up to 255 instead of 4095 because the system itself only allows for 255), and the respawn code.

So one of the goals with the projects in this would be to create character files that can be taken from one game, and put into another game with minimal hassle.

One system, the one I suggest, was to use Lua to define the characters and their scripts such as the life metre, or baddies "touch of death".

There would be a C/C++ library inbetween the Lua file and the program making use of it. All the program should have to do is call the character file, and simply place it into a situation with other character files.
_________________
[ Main Site | Kid Radd Fan Project | Forums ]

#70154 - tepples - Sat Feb 04, 2006 7:08 pm

Quirky wrote:
In doing so I decided that the code I'd written may as well just get called from C anyway and skip the script overhead. The compilation time in suitably modular code is not much greater than using GBFS and appending the scripts, with the added advantage of compile time checking, run time speed, better use of resources, ablilty to debug, etc.

What about GBAMP support? I don't know much about Lua, but it might be easier to dynamically load scripts from CF than to dynamically load compiled code.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#70311 - Quirky - Sun Feb 05, 2006 1:11 pm

tepples wrote:
What about GBAMP support? I don't know much about Lua, but it might be easier to dynamically load scripts from CF than to dynamically load compiled code.


It certainly sounds like it would be. You can compile Lua scripts into byte code too, so they would take up less space.

As for the OP's problem, if you were to use Lua for cross platform coding then I can see the advantages. But you still have to properly implement the GBA C code/wrappers (which I saw as an unnecessay extra overhead. For me, in my case).

#70522 - DakeDesu - Tue Feb 07, 2006 12:33 am

thank you for your replies.

Yes, I am aware I would need to jump through a couple hoops to get Lua to work on GBA. I am debating using tepples (I think it is teppels who maintains it) GBA Filesystem.

Anyways, I was merely asking stuff I would have to look out for. So, I guess the overhead is something to worry about...(if you know) how much is saved by using bytecode instead of text files? I wouldn't mind finding this out myself, just checking to see if anybody already knows this.

Thanks again for the replies.
_________________
[ Main Site | Kid Radd Fan Project | Forums ]