MCPcopy Create free account
hub / github.com/anjo76/angelscript / CreateScriptObject

Method CreateScriptObject

sdk/angelscript/source/as_scriptengine.cpp:5358–5468  ·  view source on GitHub ↗

interface

Source from the content-addressed store, hash-verified

5356
5357// interface
5358void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type)
5359{
5360 if( type == 0 ) return 0;
5361
5362 asCObjectType *objType = CastToObjectType(const_cast<asCTypeInfo*>(reinterpret_cast<const asCTypeInfo*>(type)));
5363 if (objType == 0) return 0;
5364 void *ptr = 0;
5365
5366 // Check that there is a default factory for ref types
5367 if( objType->beh.factory == 0 && (objType->flags & asOBJ_REF) )
5368 {
5369 // TODO: How to report the reason the object couldn't be created, without writing to the message callback? optional argument with return code?
5370 // TODO: Warn about the invalid call to message callback. Make it an optional, so the warning can be turned off
5371// asCString str;
5372// str.Format(TXT_FAILED_IN_FUNC_s_s_d, "CreateScriptObject", errorNames[-asNO_FUNCTION], asNO_FUNCTION);
5373// WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf());
5374 return 0;
5375 }
5376
5377 // Construct the object
5378 if( objType->flags & asOBJ_SCRIPT_OBJECT )
5379 {
5380 // Call the script class' default factory with a context
5381 ptr = ScriptObjectFactory(objType, this);
5382 }
5383 else if( (objType->flags & asOBJ_TEMPLATE) && (objType->flags & asOBJ_REF) )
5384 {
5385 // The registered factory that takes the object type is moved
5386 // to the construct behaviour when the type is instantiated
5387#ifdef AS_NO_EXCEPTIONS
5388 ptr = CallGlobalFunctionRetPtr(objType->beh.construct, objType);
5389#else
5390 try
5391 {
5392 ptr = CallGlobalFunctionRetPtr(objType->beh.construct, objType);
5393 }
5394 catch (...)
5395 {
5396 asCContext *ctx = reinterpret_cast<asCContext*>(asGetActiveContext());
5397 if (ctx)
5398 ctx->HandleAppException();
5399 }
5400#endif
5401 }
5402 else if( objType->flags & asOBJ_REF )
5403 {
5404 // Call the default factory directly
5405#ifdef AS_NO_EXCEPTIONS
5406 ptr = CallGlobalFunctionRetPtr(objType->beh.factory);
5407#else
5408 try
5409 {
5410 ptr = CallGlobalFunctionRetPtr(objType->beh.factory);
5411 }
5412 catch(...)
5413 {
5414 asCContext *ctx = reinterpret_cast<asCContext*>(asGetActiveContext());
5415 if( ctx )

Callers 15

ConstructMethod · 0.80
ConstructMethod · 0.80
TestFunction · 0.80
TestFunction · 0.80
TestFunction · 0.80
TestFunction · 0.80
TestFunction · 0.80
TestBStrFunction · 0.80
test_exception.cppFile · 0.80
TestFunction · 0.80
TestFunction · 0.80

Calls 2

CastToObjectTypeFunction · 0.85
HandleAppExceptionMethod · 0.80

Tested by 15

TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestBStrFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
TestFunction · 0.64
ConfigureEngineFunction · 0.64
TestScriptsFunction · 0.64