Advertisement

Adding handles to angel script objects in c++

Started by June 05, 2016 12:27 AM
1 comment, last by chasester123 8 years, 5 months 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

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

Advertisement

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