MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / run_script

Function run_script

tutorials/integration/cpp/16_sandbox.cpp:65–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63// -----------------------------------------------------------------------
64
65static bool run_script(const char * label,
66 const string & scriptPath,
67 const FileAccessPtr & fAccess,
68 CodeOfPolicies policies,
69 TextPrinter & tout) {
70 tout << "--- " << label << " ---\n";
71
72 ModuleGroup dummyLibGroup;
73 auto program = compileDaScript(scriptPath, fAccess, tout,
74 dummyLibGroup, policies);
75 if (program->failed()) {
76 tout << " Compilation FAILED (expected in sandbox demo):\n";
77 int shown = 0;
78 for (auto & err : program->errors) {
79 if (shown++ >= 3) {
80 tout << " ... and " << (int(program->errors.size()) - 3)
81 << " more error(s)\n";
82 break;
83 }
84 tout << " " << reportError(err.at, err.what, err.extra,
85 err.fixme, err.cerr);
86 }
87 return false;
88 }
89
90 Context ctx(program->getContextStackSize());
91 if (!program->simulate(ctx, tout)) {
92 tout << " Simulation failed\n";
93 return false;
94 }
95
96 auto fnTest = ctx.findFunction("test");
97 if (!fnTest) {
98 tout << " Function 'test' not found\n";
99 return false;
100 }
101
102 ctx.evalWithCatch(fnTest, nullptr);
103 if (auto ex = ctx.getException()) {
104 tout << " Exception: " << ex << "\n";
105 return false;
106 }
107 return true;
108}
109
110// -----------------------------------------------------------------------
111// Script that uses unsafe — should be blocked by sandbox

Callers 1

tutorialFunction · 0.85

Calls 7

compileDaScriptFunction · 0.85
reportErrorFunction · 0.85
getContextStackSizeMethod · 0.80
evalWithCatchMethod · 0.80
sizeMethod · 0.45
simulateMethod · 0.45
findFunctionMethod · 0.45

Tested by

no test coverage detected