• entries
    437
  • comments
    1000
  • views
    335626

What if... Pt 2

Sign in to follow this  
evolutional

78 views

Say what you see... GO!


C++


class MyVector : public ClassDefinition
{
public:

MyVector() : ClassDefinition( "Vector" )
{
DeclareProperty( CDSP_PUBLIC, PTY_FLOAT, "x" );
DeclareProperty( CDSP_PUBLIC, PTY_FLOAT, "y" );
DeclareProperty( CDSP_PUBLIC, PTY_FLOAT, "z" );

DeclareMethod( "ToString", new ClassMethodFunctor(this, &MyVector::ToString ) );
}



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

assert( inst != 0 );

float x = inst->Properties( "x" )->GetFloat();
float y = inst->Properties( "y" )->GetFloat();
float z = inst->Properties( "z" )->GetFloat();

std::cout << "Vector{" << x << ", " << y << ", " << z << "}" << std::endl;

return 0;
}
};


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

ClassInstance *inst = env.CreateInstance( &v );
inst->Properties( "x" )->Set( 100.0f );
inst->Properties( "y" )->Set( 200.0f );
inst->Properties( "z" )->Set( 300.0f );

MethodCallInfo *call = env.BeginMethodCall( inst, "ToString" );
// Add params here
call->Execute();
return 0;
}
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

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