Archive 17/01/2023.

(Solved) Internal enums in AngelScript

1vanK

In c++ I have class

class URHO3D_API CameraControllerFlowNode : public FlowNode
{
    URHO3D_OBJECT(CameraControllerFlowNode, FlowNode);

public:
    CameraControllerFlowNode(Context* context);
    void Update(float timeStep);

    enum InputPort
    {
        IN_CAMERA_NODE = 0,
        IN_MOUSE_SENSITIVITY = 1
    };
    ...
};

What better way to export it enum to angelScript? Do I have to use constants instead?

class URHO3D_API CameraControllerFlowNode : public FlowNode
{
    URHO3D_OBJECT(CameraControllerFlowNode, FlowNode);

public:
    CameraControllerFlowNode(Context* context);
    void Update(float timeStep);

    static const int IN_CAMERA_NODE = 0;
    static const int IN_MOUSE_SENSITIVITY = 1;
    ...
};
cadaver

It’s possible AS doesn’t support enums inside classes yet, though the author has already talked about it long ago. Most trouble-free option would probably be to just define an enum outside the class, and expose normally.

1vanK

There may be a lot of different types of flounodes (hunderts), so in global namespace it will be a lot of excess

1vanK

Is also impossible to register consts in class for AS?

engine->RegisterObjectProperty("CameraControllerFlowNode", "const int IN_CAMERA_NODE", offsetof(CameraControllerFlowNode, IN_CAMERA_NODE));

gives me error :frowning:

cadaver

Offsetof is for normal instance variables within the object’s memory block, consts aren’t part of that.

1vanK

Mey be is easy way for register some readonly property which just return some digit (I mean without make functions like Return0(), Return1())

slapin

I’d suggest using one of dictionary types.

1vanK

Ok, I found a solution

github.com/urho3d/Urho3D/issues/1730

slapin

Hi!
Sorry for stupid question - could you please
tell what changed as the result, i.e. what
can be done now what was not possible to do?

1vanK

RegisterCustomFlowNode<CameraControllerFlowNode>(engine, "CameraControllerFlowNode"); engine->SetDefaultNamespace("CameraControllerFlowNode"); engine->RegisterEnum("InputPort"); engine->RegisterEnumValue("InputPort", "IN_CAMERA_NODE", CameraControllerFlowNode::IN_CAMERA_NODE); engine->RegisterEnumValue("InputPort", "IN_MOUSE_SENSITIVITY", CameraControllerFlowNode::IN_MOUSE_SENSITIVITY); engine->SetDefaultNamespace("");

allows write CameraControllerFlowNode::IN_CAMERA_NODE and CameraControllerFlowNode::IN_MOUSE_SENSITIVITY in AngelScript (enum moved from global name space to class namespace)

slapin

Is it possible to register such values directly in AngelScript or not?

1vanK

Yes, angelcode.com/angelscript/sd … d2a861af18

But for register simple consts (not enums) I not found way (it required pointer)
angelcode.com/angelscript/sd … 4812013169