Jump to content

  • Log In with Google      Sign In   
  • Create Account

[Lua] Installing/compiling and usage of Lua in Windows

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 vleugel   Members   -  Reputation: 252


Posted 03 April 2013 - 12:47 PM

Hello guys,


I was just wondering, I downloaded the newest source files, compiled them and ended up with a .dll file and the compiler and intepreter .exe files.

But don't I also need a .lib file to link with my program? (as right now I'm getting linking errors when compiling example files).

If so, how do I obtain this .lib file from the source? I am using Visual studio 2012 (btw I know I could just download the binaries).


Second, I was wondering why people use the LuaBind or other wrappers, the buildin C API seems quite easy to use, what are the advantages of using these third party wrappers? Wouldn't it give trouble with newer versions of Lua? (having to wait til these wrappers update as well).


Kinds regards,




#2 vleugel   Members   -  Reputation: 252


Posted 08 April 2013 - 04:14 PM

Took me some time to find it out, but it turned out I had to write  "#define LUA_BUILD_AS_DLL", this also produces the import *.lib file along with the *.dll.

I don't think this was mentioned in the manual, at least not easy to find.


About the wrappers, still no good answer. I think most of the wrappers such as tolua and Luabind were last updated in around 2010, not sure if they support lua 5.2 and/or if these projects are dead, but in general I dislike to be dependent on too much third parties. I'll just see how far I get with Lua C API alone and if i need more I'll take a look at them.

#3 Gambini   Members   -  Reputation: 371


Posted 08 April 2013 - 09:39 PM

There's a bit of boilerplate code going on with running your own binding if you are using c++, especially when dealing with object oriented stuff. But after you get that out of the way, you can probably write a script that will parse your .h files and output binding code which would require very little fixing. That's what I've done in my most recent project, and it is always a bit of a pain binding classes, but not so much that I hate myself. http://lua-users.org/wiki/BindingCodeToLua for a place to start.


If you don't mind depending on boost, then luabind is the way to go. Boost adds an incredible amount of utilities, with the cost of keeping up with another 3rd party library. I've used luabind previously, and the binding code is simple, and easy to read/write. I'd absolutely recommend luabind if you aren't doing this for purely educational purposes.


Make sure to take a look at LuaJIT as well. You specifically said 5.2, but LuaJIT has all of 5.1 and some of 5.2 at the same time.

#4 Hodgman   Moderators   -  Reputation: 27861


Posted 08 April 2013 - 09:53 PM

You can also just include all of Lua's (or LuaJIT's) code directly into your game if you don't want a separate DLL.

Binding libraries are designed to make it easier to glue your C/C++ and Lua code together -- e.g. 1 line of code per function, instead of a dozen.
They also make everything act the same way -- e.g. With manual binding code, you could accidentally pop the wrong argument, or forget to push your return value, or forget some type-safety checks; a binding library ensures every bound function does all these actions in the exact same way.

Also, Lua is *not* an object oriented language (it does not have classes as a built in feature), but it is so flexible that it's very simple to implement OO features like classes and class-inheritance yourself, in Lua code.
Often a binding system will do this for you (implement classes) so that your C++ OO code can be sensibly translated into Lua.

The guys behind the BitSquid engine do actually recommend *not* using a binding library, and instead doing all your binding work manually using the Lua C API. Their reaoning is that these binding systems are often very inefficient, and that they hide a lot of important details, such as big differences between C/C++ and Lua. They say that by doing the binding work yourself, your Engine's Lua API will be much more Lua-oriented, rather than a C++-oriented API that's been shoehorned into Lua.

Personally, I found the existing binding libraries that I surveyed to be way too bloated and inefficient for my tastes, so I wrote an extremely simple one for use in my engine, where most of the time I can bind things to Lua with one line of code, but sometimes need a few more in complex cases - a kind of middle ground between the raw Lua API, and something like luabind..

#5 vleugel   Members   -  Reputation: 252


Posted 09 April 2013 - 09:40 AM

Ok thanks guys, guess I'll just play around with the C API and if I feel I need more I'll go to these wrappers.

And I know I can staticly link to Lua but I prefer dynamic, especialy since its very unlikely that I will ever need to change the source code.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.