Advertisement

Lua Helper/Wrapper

Started by July 21, 2011 10:37 AM
2 comments, last by dmail 13 years, 4 months ago
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!
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).

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Advertisement
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.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

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.

This topic is closed to new replies.

Advertisement