Advertisement

Can't do a valid cast

Started by April 07, 2007 04:05 PM
4 comments, last by ajwright 17 years, 7 months ago
I'm trying to pass a pointer to a derived class to a function that takes a pointer to a base class. It doesn't work through script though. Error: No matching signatures to 'attachObject(BillboardSet@&) Script Code:

SceneNode parent = this.getSceneNode();
BillboardSet @billboardSet = createBillboardSet("Blah", 20);
billboardSet.setMaterialName("PhotonGunMaterial");
parent.attachObject(cast<MovableObject>(billboardSet));

C++ Script registration:

ScriptManager::engine->RegisterGlobalFunction("BillboardSet@ createBillboardSet(const string& in, int)", asFUNCTION(ScriptSceneManager::CreateBillboardSet), asCALL_CDECL); 

...

ScriptManager::engine->RegisterObjectMethod("SceneNode", "void attachObject(MovableObject@)",  asMETHOD(SceneNode, attachObject),asCALL_THISCALL);

Actual C++:

Ogre::BillboardSet* ScriptSceneManager::CreateBillboardSet(std::string &name)
{
return sm->createBillboardSet(name);
}

...

 class _OgreExport BillboardSet : public MovableObject, public Renderable
    {
    protected:



I don't recall there being a way to tell Angelscript that a registered type derives from some other registered type. Unless there is, you'll have to register functions for each type.
Advertisement
There needs to be a way to force the cast to take place no matter what.

This doesn't work either

ScriptManager::engine->RegisterObjectBehaviour("MovableObject", asBEHAVE_ASSIGNMENT, "MovableObject @&f(const BillboardSet @& in)", asFUNCTION((Wrap::AssignCast<MovableObject*&,MovableObject*,const BillboardSet*&>)), asCALL_CDECL_OBJLAST);


Just returns INVALID_DECLARATION
Cast operations are at the very top of my to-do list. You will be able to register relationships between classes, so that AngelScript can automatically cast an object handle from one type to another.

Currently the easiest thing you can do is to register a function that does the conversion, i.e. takes a pointer of one type and returns the pointer as another type. Then you'll have to call this function to convert the handle.

Regards,
Andreas

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

I will write a global function to do it then.
Well damn, I just came on here because I couldn't find any information about registering cast operations, and here it is. Nice to know you're planning on implementing it, though. I guess I'll just work around it for now.

This topic is closed to new replies.

Advertisement