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.

DS development > Lua

#49138 - ChronoDK - Tue Jul 26, 2005 7:57 pm

This might seem silly, but I want to use Lua scripting for my DS-game. Only problem is I cant make it work.

I modified the makefile to make it compile using arm-elf-gcc instead of gcc, and it compiles nicely.

When I include it in my game using:

Code:

extern "C"
{
   #include <lua.h>
   #include <lauxlib.h>
   #include <lualib.h>
}


The command:

Code:

lua_State *L = lua_open();   /* opens Lua */


Gives the error: " undefined reference to 'lua_open' "

Is there an easy solution to this, or is trying to run standard Lua on DS too naive?

#49141 - TheMikaus - Tue Jul 26, 2005 8:06 pm

did you link the library?

#49145 - sajiimori - Tue Jul 26, 2005 8:28 pm

Lua runs great on DS -- just make sure you change the number representation from double to int. The (pre-release) 5.1 builds are especially good because they offer incremental garbage collection for consistent CPU usage in the presence of heavy allocation.

But yeah, just gotta link the library. ^_^

#49194 - ChronoDK - Wed Jul 27, 2005 7:09 am

Great - someone actually has it running :-)

I linked the library like this in my makefile (made by DesktopMan and found in his DS-template):

Code:

LIBS   := -lnds9 -Llua
LUA   := $(DEVKITPRO)/lua
LIBDIRS   :=   $(LIBNDS) $(LUA)


Is this wrong?

#49199 - TwinD - Wed Jul 27, 2005 7:33 am

lowercase L

#49232 - TheMikaus - Wed Jul 27, 2005 3:12 pm

How do you get lua to compile for the nds?

I tried just changing CC in the config file to arm-elf-gcc but when I do that it tells me it can't find arm-elf-gcc

#49234 - sajiimori - Wed Jul 27, 2005 5:39 pm

I wasn't using homebrew stuff. :x Maybe you need to set your path.

#49236 - TheMikaus - Wed Jul 27, 2005 6:14 pm

I thought that too. If I change the CC variable to use the full path to arm-elf-gcc, it craps out and gives me some wierd dll error message.

But I can compile nds examples just fine so I don't think it's an environment variable that I'm missing, but something in the config file that I didn't change right.

-edit-
Well.. I tried to compile the exampes again. Didn't work. Must have been my imagination that they did. I'll mess with my path again and see what's up.

#49239 - TheMikaus - Wed Jul 27, 2005 7:07 pm

I was messing around with it for a bit. I think you have to do more than just change the compiler. Maybe you have to set some of the flags to target it to the arm9. Also you'll have to change functions in the lua library to get it to work with the ds. Things like the print command. It probably just uses a printf or something, but you'd have to change it to consolePrintf or something like that. Not sure though.

#49243 - ChronoDK - Wed Jul 27, 2005 7:19 pm

I got it working - is using Lua in my DS-demo right now :-)

Lowercase L helped:
LIBS := -lnds9 -llua

And so did adding this in the Lua makefile:
-mthumb -mthumb-interwork -mcpu=arm9 -mtune=arm9 -DARM9

Only problem is that compiling Lua gives a lot of warnings like this:

"thumb call to arm in function .... warning: internal error: dangerous error"

"warning: interworking not enabled"

It still works... but dangerous errors sounds like something that should be fixed :-)

Any clues?

This led to a tangential discussion of the merit of Thumb instructions on the Nintendo DS, which had very little to do with Lua so it was split.

#49246 - TheMikaus - Wed Jul 27, 2005 7:42 pm

ChronoDK wrote:
I got it working - is using Lua in my DS-demo right now :-)


Are you using the lua print function or no?

--edit--
also are you testing it in an emulator or on the hardware?

#49249 - sajiimori - Wed Jul 27, 2005 8:24 pm

The print function is not built-in. The whole I/O library is optional.

#49250 - TheMikaus - Wed Jul 27, 2005 8:44 pm

yeah. I know. You can just do that lua_tonumber function to get your results and the like.

The emu/hardware question was because when I try to run it in an emulator it just does nothing(dsemu) or crashes(dualis)

I'll try something different when I get back home. Maybe my setup will be different there.