• entries
    437
  • comments
    1000
  • views
    335620

What if... Pt3

Sign in to follow this  
evolutional

86 views


struct sVertex
{
float x, y, z;
};

class Vertex : public ClassDefinition
{
public:

Vertex() : ClassDefinition( "Vertex" )
{
DeclareMethod( "ToString", new ClassMethodFunctor(this, &Vertex::ToString ) );
}


int Constructor( MethodCallInfo *p_info )
{
ClassInstance *inst = p_info->ClassInst();
assert( inst != 0 );

sVertex *p = new sVertex;
inst->SetUser( p );
return 0;
}

int ToString( MethodCallInfo *p_info )
{
ClassInstance *inst = p_info->ClassInst();
assert( inst != 0 );

sVertex *v = (sVertex*)inst->GetUser();
std::cout << "Vertex{" << v->x << ", " << v->y << ", " << v->z << "}" << std::endl;
return 0;
}

};


int main()
{
Environment env;
env.RegisterClass( &v );

Vertex defVertex;
env.RegisterClass( &defVertex );
ClassInstance *i = env.CreateInstance( "Vertex" );

sVertex *p = (sVertex *)i->GetUser();
p->x = 150.0f; p->y = 250.0f; p->z = 350.0f;

MethodCallInfo *call = env.BeginMethodCall( i, "ToString" );
// Add params if needed
call->Execute();

return 0;
}
Sign in to follow this  


3 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now