Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

RegisterGlobalFunction returning script class


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 mk1x86   Members   -  Reputation: 442

Like
0Likes
Like

Posted 17 July 2013 - 10:23 AM

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?



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
1Likes
Like

Posted 17 July 2013 - 11:02 AM

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.


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

#3 mk1x86   Members   -  Reputation: 442

Like
0Likes
Like

Posted 17 July 2013 - 12:29 PM

Using an interface worked perfectly. Thanks a lot :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS