Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


- - - - -

Proper way of creating as class in C++


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 16 July 2013 - 06:22 AM

I've googled but couldn't come up with a proper solution. I'd like to create an instance of an angelscript class from C++. My current approach:

asIObjectType* type = modBase->GetObjectTypeByName("Test");
asIScriptObject* obj = static_cast<asIScriptObject*>(engine->CreateScriptObject(type->GetTypeId()));

While this works I wondered, why CreateScriptObject returned a void pointer instead of a script object. Investigating as_scriptengine.cpp, I noticed, that the method was marked as deprecated and creation should be done via a factory. How does it work? The class is guaranteed to have a default constructor.

 

Also, what's wrong with the way it's currently done?



Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9674

Like
1Likes
Like

Posted 16 July 2013 - 07:15 AM

asIObjectType has the functions GetFactoryByDecl(), GetFactoryByIndex() and so one, that lets you get the factory functions for an object type. You can use those factory functions to create objects of that type.

#3 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 17 July 2013 - 10:38 AM

How to create instances of script classes using the factory functions is described in the manual:

 

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

 

asIScriptEngine::CreateScriptObject() is not yet deprecated, but I have plans to do so in the near future as it should take as input the asIObjectType* instead of the type id. It returns a void* instead of an asIScriptObject* because it can be used to create application registered types as well that do not derive from the asIScriptObject interface.

 

CreateScriptObject() only allows you to create objects with the default factory, i.e. with no arguments. If you need to use one of the non-default factories, then you must do it by calling the appropriate factory using an asIScriptContext as described in the manual.


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




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