🎉 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!

Cast from application class to script class

Started by
2 comments, last by Zapato 6 years ago

Following this article http://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_inheritappclass.html

When you got an instance in the script side of FooScripted it creates an instance of FooScripted_t in the C++ side and let you define the opImplCast this way:


// The script class can be implicitly cast to the C++ type through the opImplCast method
    FooScripted_t @opImplCast() { return m_obj; }

Is it possible to cast the other way round? I've a function that recieves a FooScripted_t from C++ and want to cast it to the FooScripted type. In the C++ type you got the pointer to the asIScriptObject, so I've try to manually define this with a refCast function that pass the asIScriptObject


engine->RegisterObjectMethod("FooScripted_t", "FooScripted@ opImplCast()", AngelScript::asFUNCTION(refCast), AngelScript::asCALL_CDECL_OBJLAST);

But is not possible because FooScripted 'is not a data type in a global namespace' since its defined in a script file I think. Any way to fix this? Thanks

Advertisement

You can use the "void opImplCast(?&out)" syntax, and then check at runtime if the right type is requested, and if so return the script class pointer. Unfortunately this way will not allow you to capture incorrect casts at compile time.

 

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks a lot WitchLord that was exactly what I was searching for. I used the opCast code of the scripthandle add-on and worked perfect, thanks again!.

This topic is closed to new replies.

Advertisement