Inheriting from application registered class

Started by
4 comments, last by WitchLord 8 years, 11 months ago

I'm trying to inherit from a registered class but I know that I must write some proxy methods and do it that way.

I have read the topic from the user manual but I am a little confused on how the factory function works in the example.

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


// A factory function that can be used by the script side to create
static FooScripted *Factory();

There is no actual implementation of the factory so i'm a bit confused on how the constructor is called with

"asIScriptObject *obj"

Becausse that is something that I will need at some point when calling inherited functions.

From the looks of it nothing is passed from the actual script code when doing

@m_obj = FooScripted_t();

So i'm wondering how I should implement the factory function so this example would work.

Thank you!

Advertisement

Oops. The article in the manual is obviously missing an important piece. I'll have that corrected a.s.a.p.

Anyway, the factory function can for example be implemented like this:

static FooScripted *FooScripted::Factory()
{
  asIScriptContext *ctx = asGetActiveContext();

  // Get the function that is calling the factory so we can be certain it is the FooScript class
  asIScriptFunction *func = ctx->GetFunction(0);
  if( func->GetObjectType() == 0 || std::string(func->GetObjectType()->GetName()) != "FooScripted" )
  {
    ctx->SetException("Invalid attempt to manually instantiate FooScript_t");
    return 0;
  }

  // Get the this pointer from the calling function
  asIScriptObject *obj = reinterpret_cast<asIScriptObject*>(ctx->GetThisPointer(0));

  return new FooScripted(obj);
}

The test code available in the svn might help give more clarity too (beware, the code has not really been written as a tutorial so it may be a bit confusing wink.png)

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

Thank you so much your the best!!! Also, I'm not sure exactly how much use the Xbox 360 version is getting but that is the platform I've been working on. I noticed how the support for 64 bit integers was not yet added after giving those a try and I have came up with a solution to fix that. They work the same as all the other integer types being that Xbox 360 is 64bit so the arguments can be passed in the registers as the others do starting with r3. For my fix all I did was change the size that the integers are passed on the temp stack from 4 to 8 bytes. and then I use a "ld" instead of "lwz" for the native ppc asm and then I also increase the step by 8 bytes from 4. There were a few more small changes within the part that sets up the temp stack but other then that it was a simple fix. If anyone is interested I can upload it somewhere.

I'm interested :)

If you can send me the code changes (either by e-mail or uploading them here) I'll have it checked in to the SVN.

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

Attached is the new as_callfunc_xenon.cpp. As I mentioned it now supports 64 bit integers. I would have posted it yesterday but I wanted to test it to be sure that I didn't accidentally break anything while in the process of adding the 64 bit support. I also wanted to thank you for all the amazing hard work you have done!

Thanks for the compliments. Let me know when you're ready to show your work to the public so I can add a link to it on the users list.

I've checked in the fix for Xbox 360 in revision 2169.

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

This topic is closed to new replies.

Advertisement