Using Lua with C++. Using Lua scripts with C++ classes.

Read the first part about LuaBridge here to see how to install it and use it for basic things.

You can find the complete source code of this article here

This part will show you how to register C++ classes in Lua, call member functions and how to apply scripts to something practical like putting object behaviour code in scripts.
I’m a game developer, so I’ve used examples related to gamedev but you can use Lua almost everywhere, so take a look even if you’re not interested in gamedev.
The code used in this article is as simple as possible while also remaining a complete example which you can run and compile.
I leave out the details which are irrelevant to focus on the main topic: scripts.

Continue reading

Advertisements

Re:creation dev log. October 2014. Halloween, ghosts and scripts!

Happy Halloween, everybody! Re:creation is about undeads and I think its theme fits well with Halloween. It fits even more if I add some pumpkins and scarecrows!

Continue reading

Re:creation dev log. September 2014. Drawing art, being a solo dev, fixing bugs.

Lots of time passed since the last dev log. How’s the game? It’s doing pretty well.

Some things changed, the most notable thing is that I’ve become a solo gamedev now, because the artist abandoned the project. Every sprite you see in the latest screenshots was drawn by me.

Being solo dev is hard, very hard. I spend lots of time practicing art, drawing sprites, animating them and trying to make them as good-looking as possible without spending too much time. And I still have to do programming, scripting, designing and story writing!

Continue reading

Here’s what I did this summer.

As I’m writing this the last day of the summer is approaching its end. It’s been an awesome study break. It lasted for two months and a lot of things were done in this period.

I see a lot of people who are disappointed in their summer. I’m not disappointed at all. I think I’ve accomplished some great things and while I didn’t reach some of the goals I’ve set, I’ll still work on them. My goals were not very specific (I found it very useful to set not very specific goals as I end enjoying my free time more): read some stuff, develop my game, write some blog posts and spend time with my family and SO. And I did it all. And it was great.

To be fair, I’m a little tired of this study break. I’m glad that I’ll have to study again. Hope this motivation won’t go away too soon. And now I’ll talk in detail about the things I did.

Continue reading

re:Creation dev log. Week #2 and #3. AI stuff and vacation

Week #0: Preparation

Week #1: Things are getting bigger

Week #2 and #3. AI stuff and vacation

I started to prototype the first “real” level of the game. As I was working on it, I realized all the flaws of level editor and features it lacked of. So I worked a lot on the level editor!

A lot of time was also put in optimization. Release build was always working at 60 fps without a problem, but as an object counter grew bigger and bigger Debug build started to slow down, so I decided to optimize my game a bit and now it’s running at 60 fps on Debug too. Neat.

I was also working on AI for some time. First I got NPC to go to the specified point of map.

I accidentally swapped walking animations and results were hilarious.

Continue reading

Using Lua with C++. LuaBridge makes everything easier. Variables and functions

Why use Lua?

Using scripts with C++ is great. They provide lots of flexibility and free you from using those .txt files for your configuration files and also let you write complex functions. You can modify your scripts without recompiling. This is really important because you get distracted less often. Even a short compilation can break your concentration.
And you can even design your system that even those people who don’t know how to code can create new scripts or modify existing object behavior without modifying your source code! If you want to know more reasons of what makes Lua great read the beginning of this article.

I wrote about how you can develop your own binding library in previous chapters. But this library is very basic, it doesn’t have the power some other libraries have. It’s really hard to write your own binding because it usually involves lots of templates magic and meta-programming.

I’ve tested lots of libraries and found LuaBridge to be the most awesome. It has MIT license, doesn’t have any dependencies(like Boost which some libraries use) and it doesn’t require C++11. You don’t need to build it. Just drop LuaBridge folder in your project folder, include one header and you’re ready to go!

Continue reading