(Solved) Internal enums in AngelScript

Someone can help you.

(Solved) Internal enums in AngelScript

PostPosted by 1vanK » 21 Dec 2016, 10:00

In c++ I have class
Code: Select all
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?

Code: Select all
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;
    ...
};
User avatar
1vanK
Moderator
Moderator
 
Posts: 430
Joined: 26 Jun 2015, 19:16
Location: Internet

Re: Internal enums in AngelScript

PostPosted by cadaver » 21 Dec 2016, 10:27

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.
User avatar
cadaver
Urho3D author
Urho3D author
 
Posts: 1802
Joined: 16 Jan 2014, 14:52
Location: Finland

Re: Internal enums in AngelScript

PostPosted by 1vanK » 21 Dec 2016, 10:34

There may be a lot of different types of flounodes (hunderts), so in global namespace it will be a lot of excess
User avatar
1vanK
Moderator
Moderator
 
Posts: 430
Joined: 26 Jun 2015, 19:16
Location: Internet

Re: Internal enums in AngelScript

PostPosted by 1vanK » 21 Dec 2016, 11:03

Is also impossible to register consts in class for AS?

Code: Select all
engine->RegisterObjectProperty("CameraControllerFlowNode", "const int IN_CAMERA_NODE", offsetof(CameraControllerFlowNode, IN_CAMERA_NODE));


gives me error :(
User avatar
1vanK
Moderator
Moderator
 
Posts: 430
Joined: 26 Jun 2015, 19:16
Location: Internet

Re: Internal enums in AngelScript

PostPosted by cadaver » 21 Dec 2016, 11:19

Offsetof is for normal instance variables within the object's memory block, consts aren't part of that.
User avatar
cadaver
Urho3D author
Urho3D author
 
Posts: 1802
Joined: 16 Jan 2014, 14:52
Location: Finland

Re: Internal enums in AngelScript

PostPosted by 1vanK » 21 Dec 2016, 11:26

Mey be is easy way for register some readonly property which just return some digit (I mean without make functions like Return0(), Return1())
User avatar
1vanK
Moderator
Moderator
 
Posts: 430
Joined: 26 Jun 2015, 19:16
Location: Internet

Re: Internal enums in AngelScript

PostPosted by slapin » 23 Dec 2016, 22:17

I'd suggest using one of dictionary types.
User avatar
slapin
Some active
Some active
 
Posts: 63
Joined: 15 Sep 2016, 20:15

Re: Internal enums in AngelScript

PostPosted by 1vanK » 27 Dec 2016, 20:13

User avatar
1vanK
Moderator
Moderator
 
Posts: 430
Joined: 26 Jun 2015, 19:16
Location: Internet

Re: (Solved) Internal enums in AngelScript

PostPosted by slapin » 28 Dec 2016, 21:26

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?
User avatar
slapin
Some active
Some active
 
Posts: 63
Joined: 15 Sep 2016, 20:15

Re: (Solved) Internal enums in AngelScript

PostPosted by 1vanK » 28 Dec 2016, 23:05

Code: Select all
    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)
User avatar
1vanK
Moderator
Moderator
 
Posts: 430
Joined: 26 Jun 2015, 19:16
Location: Internet

Next

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron