Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Jake Albano

Member Since 10 Aug 2010
Offline Last Active Yesterday, 09:59 PM

#5100709 Null pointer access

Posted by Jake Albano on 11 October 2013 - 10:30 PM

You need to use ctx->SetObject() to pass the context a pointer to the object which owns the method. The method doesn't own the object itself; it needs to know which instance to be called on.




#4985367 CreateUninitializedScriptObject return null for type of array<int>

Posted by Jake Albano on 30 September 2012 - 09:03 AM

CreateUninitializedScriptObject only works for script classes.

http://www.angelcode.com/angelscript/sdk/docs/manual/classas_i_script_engine.html#a8fe709ccb1d13977afb35f8726f380fb


#4985348 Passing a value into a bound class.

Posted by Jake Albano on 30 September 2012 - 07:34 AM

Yes, this is possible. You can register multiple constructors for a class:

You'll need separate factory functions:
static Img* Img_Factory() {
return new Img();
}

static Img* Img_Factory(int x, int y) {
return new Img(int x, int y);
}

And register them this way:
r = e_seScriptEngine->RegisterObjectBehaviour("Image", asBEHAVE_FACTORY, "Image@ f()", asFUNCTION(Img_Factory), asCALL_CDECL); assert(r >= 0);
r = e_seScriptEngine->RegisterObjectBehaviour("Image", asBEHAVE_FACTORY, "Image@ f(int, int)", asFUNCTIONPR(Img_Factory, (int, int), Img*), asCALL_CDECL); assert(r >= 0);

asFUNCTIONPR lets you distinguish between overloaded functions.
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_register_func.html


#4985172 Passing a value into a bound class.

Posted by Jake Albano on 29 September 2012 - 04:36 PM

You'll want to do it like this:

r = e_seScriptEngine->RegisterObjectBehaviour("Image", asBEHAVE_FACTORY, "Image@ f()", asFUNCTION(Img_Factory), asCALL_CDECL); assert(r >= 0);

Using "image" instead of "ref".


#4985130 Passing a value into a bound class.

Posted by Jake Albano on 29 September 2012 - 01:39 PM

Here's how I give my classes access to the main engine class:

When I set up the script engine, I pass the address of my engine class instance in as userdata (a void pointer):

engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetUserData(&myGameEngine);

Then, in my class constructors that need a pointer to the engine (to access window drawing, content management, etc.), I do this:

asIScriptContext* context = NULL;
asIScriptEngine* engine = NULL;
context = asGetActiveContext(); // Get the currently executing angelscript context
if ((context = asGetActiveContext()) != NULL && (engine = context->GetEngine()) != NULL)
{
	// owner is a member pointer to the engine
	owner = reinterpret_cast<Engine*>(engine->GetUserData());
}

Hopefully that helps.


#4959400 Must inherited classes in C++ be registered as reference types?

Posted by Jake Albano on 15 July 2012 - 06:58 PM

It says here that hierarchies are only supported for reference types. I think this is because a cast must be able to return a null handle if the cast fails, which can't be done with value types.

That much aside, why are you registering the value type with asOBJ_POD? A POD data structure can only hold other POD types (int, float, char and pointer), and can't have a destructor. That might what your problem actually is, since it looks as though you aren't trying to cast between base and derived types anyway.


PARTNERS