dobesv / nullc

Automatically exported from code.google.com/p/nullc
0 stars 0 forks source link

Is it possibility bind exist object to nullc? #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Is it possibility bind an existed object to nullc?
And is there any way can bind an existed c++ calss member variables to nullc?

Original issue reported on code.google.com by jiangluo...@gmail.com on 15 Mar 2012 at 2:08

GoogleCodeExporter commented 9 years ago
If you have a plain old data structure, you can define the similar one in nullc 
and in simple cases the member locations, alignment and padding will match 
between them (#pragma pack(4) is recommended). These classes can be used by 
value or by reference.

For a more complex class you should use a more robust solution using helper 
macros from nullcbind.h.

For example, a C++ class:

class SceneObject
{
public:
    SceneObject();
    ~SceneObject();

    SceneObjectPart*    AddObject(Model* model);

    void    UpdateTransform();

    unsigned    id;

    vec3    position;
    quat    orientation;
private:
    SceneObject(const SceneObject&);
    SceneObject& operator=(const SceneObject&);
};

Can be defined in nullc as follows:

namespace Level
{
    // Empty class can only be used by reference
    class   SceneObject{}

    // Definition of class properties outside of the body
    float3  SceneObject.position();
    float3  SceneObject.position(float3 ref n);
    quat    SceneObject.orientation();
    quat    SceneObject.orientation(quat ref n);

    // Definitions of class member functions outside of the body
    void    SceneObject:UpdateTransform();
    int     SceneObject:GetID();
}

And then it is possible to bind C++ class to the nullc class:

BIND_CLASS_MEMBER_GET("level", &SceneObject::position, 
"Level.SceneObject::position$", 0); // Getter has index 0
BIND_CLASS_MEMBER_SET("level", &SceneObject::position, 
"Level.SceneObject::position$", 1); // Setter has index 1
BIND_CLASS_MEMBER_GET("level", &SceneObject::orientation, 
"Level.SceneObject::orientation$", 0);
BIND_CLASS_MEMBER_SET("level", &SceneObject::orientation, 
"Level.SceneObject::orientation$", 1);

BIND_CLASS_FUNCTION("level", &SceneObject::UpdateTransform, 
"Level.SceneObject::UpdateTransform", 0);
BIND_CLASS_MEMBER_GET("level", &SceneObject::id, "Level.SceneObject::GetID", 
0); // Notice that nullc function that returns a member value can actually be 
binded directly to a C++ class member variable

Keep in mind that if a nullc function accepts or returns an array, function, 
auto ref or auto[], a specialized wrapper function must be written manually.

Original comment by Where...@gmail.com on 21 Mar 2012 at 10:06