internal This function assumes the memory for the global property is already cleared
| 428 | // internal |
| 429 | // This function assumes the memory for the global property is already cleared |
| 430 | int asCModule::InitGlobalProp(asCGlobalProperty *prop, asIScriptContext *myCtx) |
| 431 | { |
| 432 | // Call the init function for each of the global variables |
| 433 | asIScriptContext *ctx = myCtx; |
| 434 | int r = asEXECUTION_FINISHED; |
| 435 | if( prop->GetInitFunc() ) |
| 436 | { |
| 437 | if( ctx == 0 ) |
| 438 | { |
| 439 | ctx = m_engine->RequestContext(); |
| 440 | if( ctx == 0 ) |
| 441 | return asERROR; |
| 442 | } |
| 443 | |
| 444 | r = ctx->Prepare(prop->GetInitFunc()); |
| 445 | if( r >= 0 ) |
| 446 | { |
| 447 | r = ctx->Execute(); |
| 448 | if( r != asEXECUTION_FINISHED ) |
| 449 | { |
| 450 | asCString msg; |
| 451 | msg.Format(TXT_FAILED_TO_INITIALIZE_s, prop->name.AddressOf()); |
| 452 | asCScriptFunction *func = prop->GetInitFunc(); |
| 453 | |
| 454 | m_engine->WriteMessage(func->scriptData->scriptSectionIdx >= 0 ? m_engine->scriptSectionNames[func->scriptData->scriptSectionIdx]->AddressOf() : "", |
| 455 | func->GetLineNumber(0, 0) & 0xFFFFF, |
| 456 | func->GetLineNumber(0, 0) >> 20, |
| 457 | asMSGTYPE_ERROR, |
| 458 | msg.AddressOf()); |
| 459 | |
| 460 | if( r == asEXECUTION_EXCEPTION ) |
| 461 | { |
| 462 | const asIScriptFunction *function = ctx->GetExceptionFunction(); |
| 463 | |
| 464 | msg.Format(TXT_EXCEPTION_s_IN_s, ctx->GetExceptionString(), function->GetDeclaration()); |
| 465 | |
| 466 | m_engine->WriteMessage(function->GetScriptSectionName(), |
| 467 | ctx->GetExceptionLineNumber(), |
| 468 | 0, |
| 469 | asMSGTYPE_INFORMATION, |
| 470 | msg.AddressOf()); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | if( ctx && !myCtx ) |
| 477 | { |
| 478 | m_engine->ReturnContext(ctx); |
| 479 | ctx = 0; |
| 480 | } |
| 481 | |
| 482 | // Even if the initialization failed we need to set the |
| 483 | // flag that the variables have been initialized, otherwise |
| 484 | // the module won't free those variables that really were |
| 485 | // initialized. |
| 486 | m_isGlobalVarInitialized = true; |
| 487 |
nothing calls this directly
no test coverage detected