Jump to content
  • Advertisement
  • entries
    437
  • comments
    1000
  • views
    337533

What if... Pt3

Sign in to follow this  
evolutional

117 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
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!