Welcome, Guest

Author Topic: How do i bind my own type for use in JavaScript?  (Read 1483 times)

Nick

  • Administrator
  • *****
  • Posts: 475
    • View Profile
How do i bind my own type for use in JavaScript?
« on: November 04, 2013, 12:51:13 PM »
You need to overload the CoherentBind function with your own type.

For example, if you have a class Player defined as:
Code: [Select]
struct Player
{
        Player()
                : m_Name("Player")
                , m_Ammo(42)
                , m_Health(3.1415)
        {
                m_Stuff[0] = 1;
                m_Stuff[1] = 2;
                m_Stuff[2] = 3;
                m_Stuff[7] = 777;
        }
        std::string m_Name;
        unsigned m_Ammo;
        double m_Health;
        int m_Stuff[123];
};

you can implement the binding for your Player using:
Code: [Select]
void CoherentBind(Coherent::UI::Binder* binder, Player* player)
{
        if (auto type = binder->RegisterType("Player", player))
        {
                type.Property("Name", &Player::m_Name)
                        .Property("Ammo", &Player::m_Ammo)
                        .Property("Health", &Player::m_Health)
                        .Property("Stuff", &Player::m_Stuff)
                ;
        }
}

Then, you can use Player when invoking TriggerEvent.

Please check the Binding sample for a full example.
R&D Director @CoherentLabs

Tags: