🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Object Oriented LUA bindings

Started by
3 comments, last by Lacutis 19 years, 11 months ago
Hello, I see that a number of you are interfacing LUA in an OO way in your engine designs. I am currently writting a paper about various ways of interfacing scripting languages with engines and I am particularly interested in OO methods. I would be most interested to hear your approaches. Many thanks in advance Tony
<Fish>{
Advertisement
LuaBind and toLua are two OO binders I know of...

[Edited by - evolutional on August 1, 2004 3:04:36 PM]
One which I have prototyped, I have discussed on this board in some recent threads. Some other people appear to be doing the same thing.

For a game with a lot of characters (NPCs in a RPG, or anybody in a strategy), it is useful to have scripts which run over a long(ish) period. For this we use coroutines, I've figured out how to (with luabind), attach a coroutine to a native C++ object and resume it when the thing it's waiting for completes.

luabind seems to be the way to go - it handles the wrapper stuff for you.

Basically I attach a luaobject which is actually a coroutine to each actor (i.e. a character in most cases), and remember what it is they're waiting for.

In the case of something like pathfinding, the lua code calls a native method to tell it to find a path and start walking towards its destination. When it reaches its destination (or if it is blocked or something like that), it wakes up the lua code by resuming the coroutine, which can then carry out subsequent steps of its program.

Other objects can of course do the same thing at the same time, independently, without using native threads or having much of an overhead (yes, I realise that coroutines must store the lua stack, but hopefully that is fairly small)

Mark
I have recentley finished adding a LUA manager and toLua++ manager into my game engine with EASE. I would definatley check out toLua++. First of all, with just a simple command prompt command it AUTOMATICALLY generates .h and .cpp bindings for your classes that you just include into your project and you are ready to go. Now, I did check out luabind and was using it actually but here are some reasons why I switched:

1. Why bind classes yourself when toLua++ does it itself?
2. LUABind is SLOW to use and SLOW to compile, no two ways around that.

Give it a shot: http://www.codenix.com/~tolua/
-Brcolow-
I've been embedding Lua into my Mud engine and doing all the bindings by hand. It's really not that hard if you use userdata to hold C++ classes. The hardest part was figuring out the stack and metatables, after that it's a cakewalk. It takes me only a couple minutes to write a binding function for lua->C++ classes.

The Lua book is/was the biggest help, you can look at it here:
http://www.lua.org/pil/

This topic is closed to new replies.

Advertisement