Sign in to follow this  

Registering a C structure

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I'm trying to register a simple C structure from an external engine and then I want to access one as a global from a script. Currently I have... scriptEngine->RegisterObjectType("CgVector2D", sizeof(CgVector2D), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS ); scriptEngine->RegisterObjectProperty("CgVector2D", "float x", offsetof(CgVector2D, x) ); scriptEngine->RegisterObjectProperty("CgVector2D", "float y", offsetof(CgVector2D, y) ); scriptEngine->RegisterGlobalProperty("CgVector2D myGlobalVector", &myGlobalVector); Then in my script I do... myGlobalVector.x = 100; myGlobalVector.y = 100; When I've run the script there's no change in my global vector. I'm not sure about the offsetof() bit, does this work on structures? I check all the return values and nothing throws an error. On a side note I also tried to do... scriptEngine->RegisterGlobalProperty("float myGlobalVector.x", &myGlobalVector.x); scriptEngine->RegisterGlobalProperty("float myGlobalVector.y", &myGlobalVector.y); But it failed registering the Y as the name was already in use. Any ideas? Thanks Scott

Share this post


Link to post
Share on other sites
The test in tests/test_feature/source/test_vector3.cpp does exactly what you want.

My guess is that your problem lies with &myGlobalVector. Is the myGlobalVector variable a pointer? It shouldn't be, since you're taking the address of it. Or perhaps it is not a CgVector2D at all?

Regards,
Andreas

Share this post


Link to post
Share on other sites
Thanks for the reply.

I had checked the different test files and the examples but I must have missed something. I went back and put the code back in (I'd commented it out while carrying on with writing code) and now it works fine.

My gut feeling is I was inspecting the wrong variable in the debugger. It's all working now though. Thanks!

Share this post


Link to post
Share on other sites

This topic is 3627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this