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

Adding handles to angel script objects in c++

Started by
1 comment, last by chasester123 8 years ago

So this is a fairly simple question though Idk how easy the answer is.

Assume i have a c++ class cClass and an as class asClass: also assume that cClass allows reference handles.

class asClass

{

cClass @parent;

}

Now the question is how do I assign what @parent is pointing to in c++.

//c++ code

void someFunc()

{

asIScriptObject *n = asEngine->CreateUninitializedScriptObject(sometypeinfo)

cClass *c = new cClass();

//how do i assign n::parent handle to point to the memory location of c.

}

chasester

Advertisement

To do that you'll find the property 'parent' in the asClass, then get the address of the property and use it to set the pointer to the cClass.

// Find the property 'parent' in the asClass and set the pointer to cClass
for( int i = 0; i < n->GetPropertyCount(); i++ )
{
  if( string(n->GetPropertyName(i)) == "parent" )
  {
    // Set the property to point to the cClass
    *reinterpret_cast<cClass**>(n->GetAddressOfProperty(i)) = c;
    
    // Increment the refcount of cClass since asClass now holds a reference
    c->AddRef();
  }
}

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

lol i didnt know you could do that 0.0 lol ya seems straight forward engough :) thank :)

This topic is closed to new replies.

Advertisement