impr: Merge in script loader structure improvements from python branch

This commit is contained in:
WerWolv
2024-05-17 21:01:35 +02:00
parent 663b99ed64
commit f6953fd829
20 changed files with 130 additions and 80 deletions

View File

@@ -3,10 +3,8 @@
#include <stdexcept>
#if defined(OS_WINDOWS)
#include <Windows.h>
#define STRING(str) L##str
#else
#include <dlfcn.h>
#define STRING(str) str
#endif
@@ -34,38 +32,6 @@ namespace hex::script::loader {
using get_hostfxr_path_fn = int(*)(char_t * buffer, size_t * buffer_size, const get_hostfxr_parameters *parameters);
#if defined(OS_WINDOWS)
void *loadLibrary(const char_t *path) {
try {
HMODULE h = ::LoadLibraryW(path);
return h;
} catch (...) {
return nullptr;
}
}
template<typename T>
T getExport(void *h, const char *name) {
try {
FARPROC f = ::GetProcAddress(static_cast<HMODULE>(h), name);
return reinterpret_cast<T>(reinterpret_cast<uintptr_t>(f));
} catch (...) {
return nullptr;
}
}
#else
void *loadLibrary(const char_t *path) {
void *h = dlopen(path, RTLD_LAZY);
return h;
}
template<typename T>
T getExport(void *h, const char *name) {
void *f = dlsym(h, name);
return reinterpret_cast<T>(f);
}
#endif
hostfxr_initialize_for_runtime_config_fn hostfxr_initialize_for_runtime_config = nullptr;
hostfxr_get_runtime_delegate_fn hostfxr_get_runtime_delegate = nullptr;
hostfxr_close_fn hostfxr_close = nullptr;