Lua support with MAC OS X

Lua support with MAC OS X
0.0 0


Currently, I am attempting to compile the HelloLua sample for Mac OS X using XCode, and I’m having a devil of a time doing it. We hope compile a similar application that can be deployed on Mac OS X as part of a research study. Unfortunately, at this point, I cannot tell if the reason for the failed compilation and library linkage errors are the result of missing dependencies on my development computer, or if this is simply something that has not been yet made to work. The news feed at suggested that HelloLua was coming soon for the Mac OS X, though it did not mention whether one could hypothetically make a similar program on their own given the current state of the engine before those updates came.

Has anyone had success making a Mac OS X application that is similar to HelloLua in that is processes Lua scripts, or successfully created a “HelloLua” Mac project? If so, I would love to hear it, so that I just knew it was possible given the current source!


I found that if you run Cocos2d-x/scripting/lua/luajit/ You can get a libluajit.a library thats compatible with OSX.
I suggest you modify the sh script file estination first, all other libraries are sorted into platform folders, so I changed the DESTDIR to simply $DIR/mac and then create the folder named “mac” before you run the script > sh

The only last thing I came across was some GL define types that are in the common bindings as part GLES and not GL, These lines will cause not defined errors which you can wrap in ifdef or just simply comment out if you are not planning to access them in LUA


Thank you, Jason! You da man! I did see those OpenGL compilation errors which I tried to get around by commenting out those lines. It’s comforting to hear that I wasn’t the only one who ran into this.

I’ll try this build method when I get the chance and will check back in. Thanks for the quick reply!


Thank you for your help Jason, as now I have the build completing and linking properly.

However, at runtime, I see a confuddling error that I was wondering if you encountered at some point?

Namely, the program throws an EXC_BAD_ACCESS error code at line 107 of the CCLuaStack::init function. This is because m_state is set to a NULL address after the call to lua_open() below — lines 104-107 of cocos2dx_support/CCLuaStack.cpp:

bool CCLuaStack::init(void)
    m_state = lua_open();


By tracing this further, it seems like the null pointer is generated in the LuaJit memory allocation code in lj_alloc_create.

While I removed the “-m32” tag in to build the library for 64-bit deployment, I thought that this build alteration should not cause an error such as this one, though I may be wrong.

My questions for you, Jason, is:

  1. Have you ever seen this issue at runtime?
  2. Which version of LuaJIT are you using?
  3. Are you building the LuaJIT archive as 32-bit or 64-bit?

Would love to hear your thoughts if you’re willing to share them! Hopefully one of these questions holds a key to the runtime errors.

Script cutscenes, quests... with Lua or JS

To answer my last question above, once I recompiled the archive as 32-bit, and built with XCode for “My Mac 32-bit,” the HelloLua program miraculously worked! Woohoo!

Guess I should’ve tried this one last time before posting that last time!


I can’t remember what compiler issue I had a while back, not in regards to this Lua lib. I remember then I had to drop 64-bit OSX options altogether until I understood more about the -arch flags. So I have just continued to only used the 32-bit architecture flags in my OSX project and don’t have much insight on having a universal solution.

Good luck.