mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-08 22:13:17 +00:00
Implement dynlib core library for unix/darwin; not 100% about the build tags
This commit is contained in:
21
core/dynlib/lib_unix.odin
Normal file
21
core/dynlib/lib_unix.odin
Normal 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;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// +build windows
|
||||
package dynlib
|
||||
|
||||
import "core:sys/win32"
|
||||
|
||||
Reference in New Issue
Block a user