All,
Apologies if there’s obvious documentation on this, but I can’t seem to find it. I’m attempting to build a game that’s implemented in a mixture of Lua and C++. Unsurprisingly, my intent is to implement the coarse-grained game logic in Lua, with performance-critical bits in C++. So far, I’ve had not trouble implementing custom Drawable components in C++ (kudos to the team for making bootstrapping a C++ project far easier than I’m accustomed to!), but I’ve hit a bit of a snag in the Lua integration.
Calling simple Lua scripts is easy enough. Where I’m having trouble is in exposing interfaces to my custom components to script code. I believe I understand the structure and logic used for the built-in classes – as I understand it, there’s a .pkg definition file for each exposed interface, run through tolua++ to generate, e.g., NodeLuaAPI.cpp, which appears to include all the necessary Lua binding logic. So far, so good.
However, when I attempt to do the same for my own custom classes, I hit build issues at every turn, giving me the impression I’m fundamentally misunderstanding something. The package definitions seem straightforward enough. But the compiled output (via ToCppHook.lua) #includes <tolua++.h>, “lua.h”, and “LuaScript/ToLuaUtils.h”. These references appear to assume that they’ll be running within the Urho3D source build, not external projects (e.g., otherwise, I’d expect to see #include “Urho3D/LuaScript/ToLuaUtils.h”).
My next step was to hope that ToCppHook.lua was not actually necessary (it might be the case that the stuff for PODVector, et al, in there is only needed for the library itself), so I dropped the {-L […]/ToCppHook.lua from my tolua++ invocation. If I also add Source/ThirdParty/Lua/src to my include path, then manually call {tolua_MyThing_open(luaScript->GetState());} during startup, then (yay!) it actually works, and I can call {node:CreateComponent(“MyThing”)} without it crashing in the lua binding code.
My question is this – am I swimming upstream on this approach, and/or is there a simpler way to achieve my goals? I feel like my build’s more than a little precarious, reaching around into the Urho3D source tree for include paths for lua.h, and I have the sneaking suspicion that dropping ToCppHook.lua from the tolua++ invocation is causing problems I haven’t hit yet. Any guidance or pointers would be greatly appreciated. And if it happens that this is a legitimate-but-not-well-supported use-case, I’m glad to lend a hand in supporting it.
Thanks in advance,
joel.