This is where the script is compiled into bytecode that can be executed
| 345 | |
| 346 | // This is where the script is compiled into bytecode that can be executed |
| 347 | int CompileScript(asIScriptEngine *engine, const char *scriptFile) |
| 348 | { |
| 349 | int r; |
| 350 | |
| 351 | // We will only initialize the global variables once we're |
| 352 | // ready to execute, so disable the automatic initialization |
| 353 | engine->SetEngineProperty(asEP_INIT_GLOBAL_VARS_AFTER_BUILD, false); |
| 354 | |
| 355 | CScriptBuilder builder; |
| 356 | |
| 357 | // Set the pragma callback so we can detect if the script needs debugging |
| 358 | builder.SetPragmaCallback(PragmaCallback, 0); |
| 359 | |
| 360 | // Compile the script |
| 361 | r = builder.StartNewModule(engine, "script"); |
| 362 | if( r < 0 ) return -1; |
| 363 | |
| 364 | r = builder.AddSectionFromFile(scriptFile); |
| 365 | if( r < 0 ) return -1; |
| 366 | |
| 367 | r = builder.BuildModule(); |
| 368 | if( r < 0 ) |
| 369 | { |
| 370 | engine->WriteMessage(scriptFile, 0, 0, asMSGTYPE_ERROR, "Script failed to build"); |
| 371 | return -1; |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | // Execute the script by calling the main() function |
| 378 | int ExecuteScript(asIScriptEngine *engine, const char *scriptFile) |
no test coverage detected