Sourcecore/runtime.d
Documentationhttps://dlang.org/phobos/core_runtime.html
rt_loadLibrary(const char*name);rt_unloadLibrary(void*ptr);rt_init();rt_term();UnitTestResult;executed;passed;runMain;summarize;opCast(T : bool)() const;pass;fail;ModuleUnitTester = bool function();ExtendedModuleUnitTester = UnitTestResult function();CArgs;argc;argv;Runtime;initialize();terminate();args();cArgs();Example
import core.runtime;// A C library function requiring char** argumentsextern(C)void initLibFoo(int argc,char** argv);void main(){auto args = Runtime.cArgs; initLibFoo(args.argc, args.argv);}
loadLibrary()(scope const char[]name);char[]name | The name of the dynamic library to load. |
unloadLibrary()(void*p);void*p | A reference to the library to unload. |
traceHandler(TraceHandlerh, Throwable.TraceDeallocatord = null);TraceHandlerh | The new trace handler. Set to null to disable exception backtracing. |
Throwable.TraceDeallocatord | The new trace deallocator. If non-null, this will be called on exception destruction with the trace info, only when the trace handler is used to generate TraceInfo. |
traceHandler();traceDeallocator();collectHandler(CollectHandlerh);CollectHandlerh | The new collect handler. Set to null to use the default handler. |
collectHandler();extendedModuleUnitTester(ExtendedModuleUnitTesterh);moduleUnitTester(ModuleUnitTesterh);ExtendedModuleUnitTesterh | The new unit tester. Set both to null to use the default unit tester. |
Example
sharedstaticthis(){import core.runtime; Runtime.extendedModuleUnitTester = &customModuleUnitTester;}UnitTestResult customModuleUnitTester(){import std.stdio; writeln("Using customModuleUnitTester");// Do the same thing as the default moduleUnitTester: UnitTestResult result;foreach (m; ModuleInfo) {if (m) {auto fp = m.unitTest;if (fp) { ++result.executed;try { fp(); ++result.passed; }catch (Throwable e) { writeln(e); } } } }if (result.executed != result.passed) { result.runMain =false;// don't run main result.summarize =true;// print failure }else { result.runMain =true;// all UT passed result.summarize =false;// be quiet about it. }return result;}
moduleUnitTester();extendedModuleUnitTester();dmd_coverSourcePath(stringpath);stringpath | The new path name. |
NoteThis is a dmd specific setting.
dmd_coverDestPath(stringpath);stringpath | The new path name. |
NoteThis is a dmd specific setting.
dmd_coverSetMerge(boolflag);boolflag | enable/disable coverage merge mode |
NoteThis is a dmd specific setting.
trace_setlogfilename(stringname);stringname | file name |
NoteThis is a dmd specific setting.
trace_setdeffilename(stringname);stringname | file name |
NoteThis is a dmd specific setting.
profilegc_setlogfilename(stringname);stringname | file name |
NoteThis is a dmd specific setting.
runModuleUnitTests();defaultTraceHandler(void*ptr = null);void*ptr | (Windows only) The context to get the stack trace from. Whennull (the default), start from the current frame. |
import core.runtime;import core.stdc.stdio : printf;void main(){auto trace =defaultTraceHandler(null);foreach (line; trace) { printf("%.*s\n",cast(int)line.length, line.ptr); } defaultTraceDeallocator(trace);}
defaultTraceDeallocator(Throwable.TraceInfoinfo);Throwable.TraceInfoinfo | TheTraceInfo to deallocate. This should only be a value that was returned bydefaultTraceHandler. |