interface
| 5356 | |
| 5357 | // interface |
| 5358 | void *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 ) |