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

Function tutorial

tutorials/integration/cpp/06_interop.cpp:242–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240#define SCRIPT_NAME "/tutorials/integration/cpp/06_interop.das"
241
242void tutorial() {
243 TextPrinter tout;
244 ModuleGroup dummyLibGroup;
245 auto fAccess = make_smart<FsFileAccess>();
246
247 auto program = compileDaScript(getDasRoot() + SCRIPT_NAME,
248 fAccess, tout, dummyLibGroup);
249 if (program->failed()) {
250 tout << "Compilation failed:\n";
251 for (auto & err : program->errors) {
252 tout << reportError(err.at, err.what, err.extra,
253 err.fixme, err.cerr);
254 }
255 return;
256 }
257
258 Context ctx(program->getContextStackSize());
259 if (!program->simulate(ctx, tout)) {
260 tout << "Simulation failed:\n";
261 for (auto & err : program->errors) {
262 tout << reportError(err.at, err.what, err.extra,
263 err.fixme, err.cerr);
264 }
265 return;
266 }
267
268 auto fnTest = ctx.findFunction("test");
269 if (!fnTest) {
270 tout << "Function 'test' not found\n";
271 return;
272 }
273
274 ctx.evalWithCatch(fnTest, nullptr);
275 if (auto ex = ctx.getException()) {
276 tout << "Exception: " << ex << "\n";
277 }
278}
279
280int main(int, char * []) {
281 NEED_ALL_DEFAULT_MODULES;

Callers 1

mainFunction · 0.70

Calls 7

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

Tested by

no test coverage detected