Jump to content
  • Advertisement
Sign in to follow this  
luggage

Registering a C structure

This topic is 3845 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!