Archive 17/01/2023.

[SOLVED] How Node::GetComponent lua binding works?

KonstantTom

How Node::GetComponent lua binding works?
It works with any types of components. I need to implement this for some my classes. For example I has this function:

StatesEngine::StateObject is basic class such as Urho3D::Component.
I can use all Urho3D::NavigationMesh functionality if I call:

But if I call it I can use only StatesEngine::StateObject functions.

In Node.pkg I see only:

// template <class T> T* GetComponent() const; Component* GetComponent(const String type, bool recursive = false) const;

In my StateObjectsManager.pkg:

Is it ancient magic of Urho3D?

cadaver

The “magic” is the helper function ToluaPushObject, which determines the object’s type dynamically through the Object::GetType() type identification system (set up with URHO3D_OBJECT macro).

When bindings are generated, the init code in Source/Urho3D/LuaScripts/pkgs/ToCppHook.lua instructs this function to be used for Component, UIElement and Resource subclasses. In theory it looks like this could be simplified to say that it should be used for all Object subclasses.

As for the base class functions, these should get included as long as your pkg file defines the base class relationship, but I’m not familiar with all the ways how this could go wrong.

KonstantTom

Big thanks! Now all works! :slight_smile: