lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2009/12/14 Joe Andresen <>
Hello All,

This is my first ever email to a mail list (weird i know).
I have been reading this list for a while and have a blog on my
game engine that uses lua bound to c++.
here is a link, the video a bunch of posts down talks about how i use Lua with C++.

I have a pretty strong opinion about the matter. I use luna to wrap my Engine kind of.

I basically have a main EngineManager class which exposes some API like functions to lua for
creating, moving, and deleting graphical assets. Lua is to handle all of the game logic.

I push my class on in the init stage of the engine, using userdata and the registry, basically using what luna does
only pushing the actual object. and the all access to anything else is from lua is done through the EngineManager's provided Lua API.

I'm not a HUGE fan of binding C++ classes to lua, since i feel like architecturally it defeats the purpose of
the advantages of the language. Tables provide enough OOP like functionality and I use an ID/HashTable
system to refer to any objects in C++. Pointers could be used, but there are pros and cons for doing it either way.

Anyways. the video in my blog goes into a bit more detail.


PS. How do I reply to the message properly...?

I feel it is a matter of weighing the pros and cons of every feasible way of integrating two languages.
The method you describe is perfectly valid and is used and recommended in publications, yet also has cons.
To me bindings do more than just bind classes they may also:
Provide generic methods for calling Lua methods.
Provide generic means of passing parameters to Lua.
Error check.
Provide generic methods as a default for storing, accessing and adding to tables.
Ease integration of the Languages.
Decouple the scripting language used allowing for others to be easily swapped in.
Decouple the language from core code, if required.
Provide compile time checks on your code.
Provide unit tests so you are sure they do the correct thing.
Provide extending C++ classes in Lua.
Provide overriding C++ member functions in Lua.
Provide operator usage via metamethods.

To me the method you suggest improves the speed of calling C++ from Lua, yet increases debugging and integration time.

PS. How do I reply to the message properly...?
Do you mean ethically should you bottom post or how to click the reply button :)