Main contents

Archive for the 'lua' Category

Lua

July 6th, 2008

Spent some time exploring Lua.  This language has caught my interest, not least because Lightroom is largely implemented in it.  I’ve played around with it briefly before on Linux, and I have to admit that the experience of getting it up and running is much less painful on Ubuntu than on Windows.  $ apt-get install lua is much faster than downloading tarballs, creating visual studio solutions from scratch, mucking around with paths and dependencies and resolving any number of LNK2005 errors.  But I got there in the end.  Specifically, I

  • Downloaded the Lua source from Lua.org.
  • Created a Visual Studio DLL project containing all the source files apart from lua.c and luac.c
  • Built this DLL to create lua.dll
  • Created another project with just lua.c, and linked to the above DLL
  • Built this project to create lua.exe. Now I’ve got a lua environment.
  • Downloaded the luabind source from Rasterbar Software. This seems to be based on the powerful Boost.Python library, which I’ve had a lot of success with in the past.
  • Created another Visual Studio project for luabind, add the luabind source files and link with lua.dll.  Luabind does come with a bjam make file, but I usually find bjam a complete headache to use.
  • Created yet another project with the sample code from the luabind tutorial, built and linked against the luabind library and lua.dll

After all this, (and several hours of tweaking linker settings) I’ve now got the tutorials working to the extent that I can now do two things.  I can expose C++ functions into a Lua program, which is very handy, and something I’ve found very useful in Python.  But of course, the big draw to Lua is that it can be embedded in an existing C or C++ program!  So now I’ve also got to the point where I can contain a Lua interpreter within a C++ application, pass a string of Lua code to that interpreter to be executed, and even let provide the interpeter with the ability to call out to C++ functions elsewhere in the program.

So despite the the hoops I had to jump through, I think this could be a very powerful environment.  Now I just need to learn the Lua language itself, but as they say, if you can’t learn a new language in a weekend you shouldn’t call yourself a programmer.

Posted in Programming, c++, lua | No Comments »