Extending MOAI Lua host with additional 3rd party libraries

New to Moai? Get started here with our best tips and tutorials.

Extending MOAI Lua host with additional 3rd party libraries

Postby stun » Sat Sep 29, 2012 1:00 pm

This is a brief how to which I'm posting here because it might save you 5 minutes (or me 5 minutes if I do this again). Recently I added lua 'bit ops' to the MOAI host so I could have bit flags. It was completely painless and here's a little recipe:

- First get Lua bit ops from: http://bitop.luajit.org/

- Extract it to 3rdParty/luabitop. Under 3rdParty in the moai-sdk source code you'll see a bunch of other lua extensions. We're just going to make bitop one of those.

- Add the source code to your solution or make file: Under the VS2010 solution I added a new folder: 'Libraries/luaext/luabit' and made sure it included the 'bit.c' file from the luabit source extracted above.

- Edit src/aku/AKU-luaext.h: Follow the pattern and add:

Code: Select all
  1. AKU_API void    AKUExtLoadLuabit();



- Provide the trivial implementation in src/aku/AKU-luaext.cpp, again following the existing pattern you'll see:

Code: Select all
  1. extern "C" {

  2.         // bit.c implements this

  3.         extern int luaopen_bit                          ( lua_State *L );

  4. }

  5.  

  6. void AKUExtLoadLuabit () {

  7.         lua_State* state = AKUGetLuaState ();

  8.         luaopen_bit( state );

  9. }



- Get the GLUTHost.cpp to call this code (search for GLUTHOST_USE_LUAEXT and you'll find the block of code that loads all the existing extensions):

Code: Select all
  1. #ifdef GLUTHOST_USE_LUAEXT

  2.         AKUExtLoadLuabit ();

  3. #endif



- Try it out. Under MOAI Lua code the 'bit' module is automatically available so you can do things like:

Code: Select all
  1. flags = bit.bor(flags, MY_FLAG)

stun
 
Posts: 74
Joined: Wed Jul 25, 2012 2:31 pm

Re: Extending MOAI Lua host with additional 3rd party librar

Postby ibisum » Mon Oct 01, 2012 12:00 am

Nice work! I like the idea of bitops in MOAI by default - you going to submit a pull request on mainline moai-dev for this?
;
--
ibisum@gmail.com
Got a MOAI snippet? Please consider adding it to http://moaisnippets.info
User avatar
ibisum
 
Posts: 1026
Joined: Mon Oct 17, 2011 1:11 am
Location: Vienna, Austria

Re: Extending MOAI Lua host with additional 3rd party librar

Postby stun » Mon Oct 01, 2012 1:11 pm

I had considered it, but to be honest I'm a total GIT newbie so didn't want to screw anything up! I'm familiar with Mercurial so GIT can't be too hard to pick up :). I'll look into it.
stun
 
Posts: 74
Joined: Wed Jul 25, 2012 2:31 pm

Re: Extending MOAI Lua host with additional 3rd party librar

Postby sgeos » Tue Oct 02, 2012 7:18 am

You may want to take a look at my wiki article on the same topic.
Any original code posted by me is released via the CC0 Public Domain Dedication. It is in the public domain. Do whatever you want with it.
User avatar
sgeos
 
Posts: 241
Joined: Sat Apr 28, 2012 4:42 am
Location: Married in Japan.

Re: Extending MOAI Lua host with additional 3rd party librar

Postby stun » Wed Oct 31, 2012 11:26 pm

SGeos, nice to know I hadn't missed any steps! I can fill out the VS2010 section of your wiki article if you want since I'm using VS2010...
stun
 
Posts: 74
Joined: Wed Jul 25, 2012 2:31 pm

Re: Extending MOAI Lua host with additional 3rd party librar

Postby todd » Thu Nov 01, 2012 10:16 am

Thanks for writing this!
User avatar
todd
 
Posts: 262
Joined: Fri Mar 25, 2011 1:11 pm

Re: Extending MOAI Lua host with additional 3rd party librar

Postby stun » Tue Nov 06, 2012 12:46 pm

The luabitop changes I made to MOAI 1.3 are here:

https://github.com/c0d3monk33/moai-dev/ ... c195557322
stun
 
Posts: 74
Joined: Wed Jul 25, 2012 2:31 pm


Return to New Users

Who is online

Users browsing this forum: No registered users and 0 guests

cron

x