mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Allow loading current process on windows as well.
This commit is contained in:
parent
d803561582
commit
e37be627e0
@ -202,6 +202,7 @@ static const JanetAbstractType janet_struct_type = {
|
||||
typedef struct {
|
||||
Clib clib;
|
||||
int closed;
|
||||
int is_self;
|
||||
} JanetAbstractNative;
|
||||
|
||||
static const JanetAbstractType janet_native_type = {
|
||||
@ -1115,6 +1116,7 @@ JANET_CORE_FN(janet_core_raw_native,
|
||||
JanetAbstractNative *anative = janet_abstract(&janet_native_type, sizeof(JanetAbstractNative));
|
||||
anative->clib = lib;
|
||||
anative->closed = 0;
|
||||
anative->is_self = path == NULL;
|
||||
return janet_wrap_abstract(anative);
|
||||
}
|
||||
|
||||
@ -1138,6 +1140,7 @@ JANET_CORE_FN(janet_core_native_close,
|
||||
janet_fixarity(argc, 1);
|
||||
JanetAbstractNative *anative = janet_getabstract(argv, 0, &janet_native_type);
|
||||
if (anative->closed) janet_panic("native object already closed");
|
||||
if (anative->is_self) janet_panic("cannot close self");
|
||||
anative->closed = 1;
|
||||
free_clib(anative->clib);
|
||||
return janet_wrap_nil();
|
||||
|
@ -912,6 +912,14 @@ char *error_clib(void) {
|
||||
error_clib_buf[strlen(error_clib_buf) - 1] = '\0';
|
||||
return error_clib_buf;
|
||||
}
|
||||
|
||||
Clib load_clib(const char *name) {
|
||||
if (name == NULL) {
|
||||
return GetModuleHandle(NULL);
|
||||
} else {
|
||||
return LoadLibrary(name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Alloc function macro fills */
|
||||
|
@ -144,9 +144,9 @@ typedef int Clib;
|
||||
#elif defined(JANET_WINDOWS)
|
||||
#include <windows.h>
|
||||
typedef HINSTANCE Clib;
|
||||
#define load_clib(name) LoadLibrary((name))
|
||||
#define free_clib(c) FreeLibrary((c))
|
||||
#define symbol_clib(lib, sym) GetProcAddress((lib), (sym))
|
||||
Clib load_clib(const char *name);
|
||||
char *error_clib(void);
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
|
Loading…
Reference in New Issue
Block a user