Sign in to follow this  
mk1x86

RegisterGlobalFunction returning script class

Recommended Posts

mk1x86    445

Sorry for creating so many threads recently. I've got some kind of chicken and egg problem.

 

There's a class "EffectC" implemented in C++ and also an angelscript class "Effect" which is loaded in a "base" module. When EffectC is created, it creates an instance of "Effect" which has a constructor, taking EffectC as parameter:

shared class Effect : DynamicBase, Object
{
	private EffectC@ self;
	Effect(EffectC@ obj) { @self = obj; }
	//...
}

Now here's the problem: In Angelscript I'd like to create a new effect, calling a globalFunction "Effect@ createEffect()". This should actually be a registered C++ function, that creates "EffectC", which in turn creates an instance of "Effect" and returns it.

r = engine->RegisterGlobalFunction("Effect@ createEffect(uint res)", asFUNCTION(asCreateEffect), asCALL_CDECL);

This doesn't work, obviously, because the engine doesn't know about "Effect" (identifier "Effect" is not a data type).

Is it even possible to use a C++ function and return an asIScriptObject?

Share this post


Link to post
Share on other sites
WitchLord    4677

It is possible for registered function to create and return script classes. Though you can't register the function with a declaration to return the class directly as the class type is not known at the time of registration. To solve this you can either register an interface that the script class must implement, or use the ScriptHandle add-on to return a generic reference.

 

 

The manual has an article for how to use script classes from the application:

 

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

 

It ought to answer your questions. If not, please let me know so I can improve it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this