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

Function CompileScript

sdk/samples/asrun/source/main.cpp:347–375  ·  view source on GitHub ↗

This is where the script is compiled into bytecode that can be executed

Source from the content-addressed store, hash-verified

345
346// This is where the script is compiled into bytecode that can be executed
347int 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
378int ExecuteScript(asIScriptEngine *engine, const char *scriptFile)

Callers 1

mainFunction · 0.70

Calls 6

SetEnginePropertyMethod · 0.80
SetPragmaCallbackMethod · 0.80
StartNewModuleMethod · 0.80
AddSectionFromFileMethod · 0.80
BuildModuleMethod · 0.80
WriteMessageMethod · 0.80

Tested by

no test coverage detected