Hi Stoo,
Stoo wrote:Okay, so the "parent class" piece points to something outside Lua - I can see how that would complicate inheritance.
Well, yes and no: The metatables are in the registry (a part of the Lua script state), but the registry is only available via the C API.
The key idea is to prevent Lua code from accidentally tampering with the C++ controlled parts of the code. The flexibility is preserved, though: Simply assign data or methods to the entity instances directly (
function myEntity:myNewMethod() ... end
), and it should work.
I've been reading the online version of the pil book since I started messing with the scripting - so I probably know just enough to be dangerous
The whole metatable-as-parent concept is why I was confused about why the player objects couldn't inherit; it seemed so flexible...
Well, I think it is, though I agree that on the C API side, things quickly tend to get ... involved. (On the one hand, I find it easy enough, but on the other hand, I also find myself re-reading the PiL2 book whenever I made a longer pause in using it.)
Yeah, I was looking forward to seeing what you updated!
My latest updates in the SVN head revision, though not yet completely implementing what I have in mind (see
http://trac.cafu.de/browser/cafu/trunk/ ... tState.hpp for details), should solve the problems we discussed above:
You can now call methods on an entity (as before, from
EntTriggerT
):
Code: Select all
ScriptState->CallEntityMethod(this, "OnTrigger", "G", Activator->Name.c_str());
but now also call any global function, with input/output parameter passing:
Code: Select all
ScriptState->GetScriptState()->Call("functionname", Signature, ...);
and run arbitrary chunks of Lua code:
Code: Select all
ScriptState->GetScriptState()->Run("a = 1; b = 2; c();");
(The double "ScriptState" in
ScriptState->GetScriptState()
is one of the awkward things that will disappear again in one of the next revisions!)
Yeah, I was looking forward to seeing what you updated! I'm just running from your last binary release though - how often do those come out?
Binary??
Easiest and most up-to-date was if you used the SVN repository.
I also update the source code packages and binary release these days much more frequently than before -- I'll start another updates run later today.