Jump to content
  • Advertisement
Sign in to follow this  
urbanyoung

Lua Helper/Wrapper

This topic is 2543 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
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 Lua_icxx and Lua Wrapper. Failing all that see the Lua wiki for a list of binding libraries.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!