🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Registering a C structure
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
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
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
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!
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement