Implement dynlib core library for unix/darwin; not 100% about the build tags

This commit is contained in:
Scitoshi Nakayobro
2019-12-30 19:09:59 -05:00
parent 7e271310ff
commit d79ee7d530
2 changed files with 22 additions and 0 deletions

21
core/dynlib/lib_unix.odin Normal file
View File

@@ -0,0 +1,21 @@
// +build linux, darwin
package dynlib
import "core:os"
load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
flags := os.RTLD_NOW;
if global_symbols do flags |= os.RTLD_GLOBAL;
lib := os.dlopen(path, flags);
return Library(lib), lib != nil;
}
unload_library :: proc(library: Library) {
os.dlclose(rawptr(library));
}
symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
ptr = os.dlsym(rawptr(library), symbol);
found = ptr != nil;
return;
}

View File

@@ -1,3 +1,4 @@
// +build windows
package dynlib
import "core:sys/win32"