diff --git a/BeefLibs/corlib/src/System/Environment.bf b/BeefLibs/corlib/src/System/Environment.bf index 3e7ae55e..bf806e1b 100644 --- a/BeefLibs/corlib/src/System/Environment.bf +++ b/BeefLibs/corlib/src/System/Environment.bf @@ -48,6 +48,14 @@ namespace System }); } + public static void GetModuleFilePath(String outPath) + { + Platform.GetStrHelper(outPath, scope (outPtr, outSize, outResult) => + { + Platform.BfpDynLib_GetFilePath((.)Internal.[Friend]sModuleHandle, outPtr, outSize, (Platform.BfpLibResult*)outResult); + }); + } + public static uint32 TickCount { get diff --git a/BeefLibs/corlib/src/System/Internal.bf b/BeefLibs/corlib/src/System/Internal.bf index 08fa6108..b3ae5134 100644 --- a/BeefLibs/corlib/src/System/Internal.bf +++ b/BeefLibs/corlib/src/System/Internal.bf @@ -70,6 +70,13 @@ namespace System static extern int32 Test_Query(); static extern void Test_Finish(); + static void* sModuleHandle; + [AlwaysInclude] + static void SetModuleHandle(void* handle) + { + sModuleHandle = handle; + } + public static Object ObjectAlloc(TypeInstance typeInst, int size) { #if BF_ENABLE_OBJECT_DEBUG_FLAGS diff --git a/IDE/mintest/minlib/src/System/Internal.bf b/IDE/mintest/minlib/src/System/Internal.bf index ca9b03fc..16c978ad 100644 --- a/IDE/mintest/minlib/src/System/Internal.bf +++ b/IDE/mintest/minlib/src/System/Internal.bf @@ -70,6 +70,13 @@ namespace System static extern int32 Test_Query(); static extern void Test_Finish(); + static void* sModuleHandle; + [AlwaysInclude] + static void SetModuleHandle(void* handle) + { + sModuleHandle = handle; + } + public static Object ObjectAlloc(TypeInstance typeInst, int size) { #if BF_ENABLE_OBJECT_DEBUG_FLAGS diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 4fa30cef..62f81f9e 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -1644,6 +1644,14 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) bfModule->mBfIRBuilder->CreateCondBr(cmpResult, initBlock, initSkipBlock); bfModule->mBfIRBuilder->AddBlock(initBlock); bfModule->mBfIRBuilder->SetInsertPoint(initBlock); + + auto moduleMethodInstance = bfModule->GetInternalMethod("SetModuleHandle", 1); + if (moduleMethodInstance) + { + SmallVector args; + args.push_back(bfModule->mBfIRBuilder->GetArgument(0)); + bfModule->mBfIRBuilder->CreateCall(moduleMethodInstance.mFunc, args); + } } // Do the LoadLibrary calls below priority 100 @@ -1841,7 +1849,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BfIRBlock deinitSkipBlock; if (project->mTargetType == BfTargetType_BeefDynLib) - { + { auto deinitBlock = bfModule->mBfIRBuilder->CreateBlock("doDeinit", false); deinitSkipBlock = bfModule->mBfIRBuilder->CreateBlock("skipDeinit", false); auto cmpResult = bfModule->mBfIRBuilder->CreateCmpEQ(bfModule->mBfIRBuilder->GetArgument(1), bfModule->mBfIRBuilder->CreateConst(BfTypeCode_Int32, 0));