mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-26 05:25:00 -07:00
hot reloading mule
This commit is contained in:
@@ -93,6 +93,7 @@ if "%ryan_scratch%"=="1" %compile% ..\src\scratch\ryan_scratch
|
||||
if "%look_at_raddbg%"=="1" %compile% ..\src\scratch\look_at_raddbg.c %compile_link% %out%look_at_raddbg.exe
|
||||
if "%mule_main%"=="1" del vc*.pdb mule*.pdb && %cl_release% /c ..\src\mule\mule_inline.cpp && %cl_release% /c ..\src\mule\mule_o2.cpp && %cl_debug% /EHsc ..\src\mule\mule_main.cpp ..\src\mule\mule_c.c mule_inline.obj mule_o2.obj
|
||||
if "%mule_module%"=="1" %compile% ..\src\mule\mule_module.cpp %compile_link% %link_dll% %out%mule_module.dll
|
||||
if "%mule_hotload%"=="1" %compile% ..\src\mule\mule_hotload_main.c %compile_link% %out%mule_hotload.exe & %compile% ..\src\mule\mule_hotload_module_main.c %compile_link% %link_dll% %out%mule_hotload_module.dll
|
||||
popd
|
||||
|
||||
:: --- Unset ------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int lib_loaded = 0;
|
||||
HANDLE lib = {0};
|
||||
FILETIME lib_last_filetime = {0};
|
||||
int (*get_number)(void) = 0;
|
||||
for(;;)
|
||||
{
|
||||
//- rjf: hot-load dll
|
||||
{
|
||||
HANDLE file = CreateFileA("mule_hotload_module.dll", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
FILETIME modified = {0};
|
||||
if(GetFileTime(file, 0, 0, &modified) &&
|
||||
CompareFileTime(&lib_last_filetime, &modified) == -1)
|
||||
{
|
||||
for(int reloaded = 0; !reloaded;)
|
||||
{
|
||||
if(lib_loaded)
|
||||
{
|
||||
FreeLibrary(lib);
|
||||
lib_loaded = 0;
|
||||
}
|
||||
BOOL copy_worked = CopyFile("mule_hotload_module.dll", "mule_hotload_module_temp.dll", 0);
|
||||
lib = LoadLibraryA("mule_hotload_module_temp.dll");
|
||||
if(lib != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
reloaded = 1;
|
||||
lib_last_filetime = modified;
|
||||
get_number = (int(*)(void))GetProcAddress(lib, "get_number");
|
||||
lib_loaded = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(file);
|
||||
}
|
||||
int number = get_number();
|
||||
printf("got a number: %i\n", number);
|
||||
if(number == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Sleep(1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
__declspec(dllexport) int
|
||||
get_number(void)
|
||||
{
|
||||
int sum = 0;
|
||||
for(int i = 0; i < 100; i += 1)
|
||||
{
|
||||
sum += i;
|
||||
sum += i;
|
||||
sum += 1;
|
||||
}
|
||||
sum = 0;
|
||||
return sum;
|
||||
}
|
||||
Reference in New Issue
Block a user