Sign in to follow this  
urbanyoung

Lua Helper/Wrapper

Recommended Posts

urbanyoung    100
Hi,

I have a project that heavily uses Lua scripts. Multiple scripts can be loaded at once and generally (all except when a script loads), when I call a function in one script I call it in all others. I have a system that works quite well for this, but it's come time to redesign my code. As such I was looking over how I call Lua functions and I'm sure there must be a better way. Currently I have about 4 different functions for calling Lua functions: genericcall (no return value, all integer params) rgenericcall (same as generic call but with integer return value), AdvancedCall/rAdvancedCall which take a vector of parameters of differing types (strings, numbers etc).

I really don't like how I have to call a script function that takes, for example, an integer and a string parameter. What I currently do is build a vector that contains the parameters I want to pass to the script, and each entry in the vector uses a struct that specifies the data and its type. This method gets quite messy when I want to pass numerous variables to a function.

So, this is my question. Are there any nice (simple, lightweight) wrappers that have more elegant ways of calling functions than my current method?

Thanks!

Share this post


Link to post
Share on other sites
Nanoha    2682
Is something like luabind an option for you? You can call a function with any number of parameters. I think its using boost to do this (I forget the exact thing).

Share this post


Link to post
Share on other sites
Roots    1625
I use Luabind and I wouldn't call it simple nor lightweight. Its an extremely powerful product, but it also has some headaches when it comes to building it into your software and produces the most crazy compiler errors when you get something wrong. However once its setup and working, its absolutely fantastic.

There are other Lua wrapper libraries as well. I think there's LuaPlus, and tolua++ or something. We evaluated all the different libraries years ago and decided to go with Luabind. I would suggest you just google "Lua binding library" and research each product you find and evaluate which one (if any) fits your needs the best. You can always write your own binding library as well, but I'd use caution if you're planning to do this as it is not a trivial amount of work to do. One of our developers originally stated that he was going to write our binding code by hand, and I let him pursue that but he never got too far with it and after he left our team some time later, we had to scrap everything he did and replace it with Luabind.

Share this post


Link to post
Share on other sites
dmail    116
I know of a certain library I like which has the syntax helper.call("funcname","param1",int2) :)
There have also been a number of new libraries released lately which are said to be simple wrappers such as [url="http://lua-icxx.sourceforge.net/"]Lua_icxx[/url] and [url="https://bitbucket.org/alexames/luawrapper"]Lua Wrapper[/url]. Failing all that see the [url="http://lua-users.org/wiki/BindingCodeToLua"]Lua wiki[/url] for a list of binding libraries.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this