internal
| 350 | |
| 351 | // internal |
| 352 | int asCModule::CallInit(asIScriptContext *myCtx) |
| 353 | { |
| 354 | if( m_isGlobalVarInitialized ) |
| 355 | return asERROR; |
| 356 | |
| 357 | // Each global variable needs to be cleared individually |
| 358 | asCSymbolTableIterator<asCGlobalProperty> it = m_scriptGlobals.List(); |
| 359 | while( it ) |
| 360 | { |
| 361 | asCGlobalProperty *desc = *it; |
| 362 | memset(desc->GetAddressOfValue(), 0, sizeof(asDWORD)*desc->type.GetSizeOnStackDWords()); |
| 363 | it++; |
| 364 | } |
| 365 | |
| 366 | // Call the init function for each of the global variables |
| 367 | asIScriptContext *ctx = myCtx; |
| 368 | int r = asEXECUTION_FINISHED; |
| 369 | it = m_scriptGlobals.List(); |
| 370 | while( it && r == asEXECUTION_FINISHED ) |
| 371 | { |
| 372 | asCGlobalProperty *desc = *it; |
| 373 | it++; |
| 374 | if( desc->GetInitFunc() ) |
| 375 | { |
| 376 | if( ctx == 0 ) |
| 377 | { |
| 378 | ctx = m_engine->RequestContext(); |
| 379 | if( ctx == 0 ) |
| 380 | break; |
| 381 | } |
| 382 | |
| 383 | r = InitGlobalProp(desc, ctx); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | if( ctx && !myCtx ) |
| 388 | { |
| 389 | m_engine->ReturnContext(ctx); |
| 390 | ctx = 0; |
| 391 | } |
| 392 | |
| 393 | // Even if the initialization failed we need to set the |
| 394 | // flag that the variables have been initialized, otherwise |
| 395 | // the module won't free those variables that really were |
| 396 | // initialized. |
| 397 | m_isGlobalVarInitialized = true; |
| 398 | |
| 399 | if( r != asEXECUTION_FINISHED ) |
| 400 | return asINIT_GLOBAL_VARS_FAILED; |
| 401 | |
| 402 | return asSUCCESS; |
| 403 | } |
| 404 | |
| 405 | // internal |
| 406 | // This function assumes the memory for the global property is already cleared |
nothing calls this directly
no test coverage detected