mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 14:18:47 +00:00
Add bool return to dynlib.initialize_symbols.
This commit is contained in:
@@ -24,9 +24,9 @@ main :: proc() {
|
|||||||
// Load symbols from `lib.dll` into Symbols struct.
|
// Load symbols from `lib.dll` into Symbols struct.
|
||||||
// Each struct field is prefixed with `foo_` before lookup in the DLL's symbol table.
|
// Each struct field is prefixed with `foo_` before lookup in the DLL's symbol table.
|
||||||
// The library's Handle (to unload) will be stored in `sym._my_lib_handle`. This way you can load multiple DLLs in one struct.
|
// The library's Handle (to unload) will be stored in `sym._my_lib_handle`. This way you can load multiple DLLs in one struct.
|
||||||
count := dynlib.initialize_symbols(&sym, "lib.dll", "foo_", "_my_lib_handle")
|
count, ok := dynlib.initialize_symbols(&sym, "lib.dll", "foo_", "_my_lib_handle")
|
||||||
defer dynlib.unload_library(sym._my_lib_handle)
|
defer dynlib.unload_library(sym._my_lib_handle)
|
||||||
fmt.printf("%v symbols loaded from lib.dll (%p).\n", count, sym._my_lib_handle)
|
fmt.printf("ok: %v. %v symbols loaded from lib.dll (%p).\n", ok, count, sym._my_lib_handle)
|
||||||
|
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
fmt.println("42 + 42 =", sym.add(42, 42))
|
fmt.println("42 + 42 =", sym.add(42, 42))
|
||||||
|
|||||||
@@ -108,18 +108,17 @@ Optionally also takes the struct member to assign the library handle to, `__hand
|
|||||||
This allows using one struct to hold library handles and symbol pointers for more than 1 dynamic library.
|
This allows using one struct to hold library handles and symbol pointers for more than 1 dynamic library.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
* -1 if the library could not be loaded.
|
* `-1, false` if the library could not be loaded.
|
||||||
* The number of symbols assigned on success.
|
* The number of symbols assigned on success. `ok` = true if `count` > 0
|
||||||
|
|
||||||
See doc.odin for an example.
|
See doc.odin for an example.
|
||||||
*/
|
*/
|
||||||
initialize_symbols :: proc(symbol_table: ^$T, library_name: string, symbol_prefix := "", handle_field_name := "__handle") -> (count: int) where intrinsics.type_is_struct(T) {
|
initialize_symbols :: proc(symbol_table: ^$T, library_name: string, symbol_prefix := "", handle_field_name := "__handle") -> (count: int, ok: bool) where intrinsics.type_is_struct(T) {
|
||||||
assert(symbol_table != nil)
|
assert(symbol_table != nil)
|
||||||
ok: bool
|
|
||||||
handle: Library
|
handle: Library
|
||||||
|
|
||||||
if handle, ok = load_library(library_name); !ok {
|
if handle, ok = load_library(library_name); !ok {
|
||||||
return -1
|
return -1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// `symbol_table` must be a struct because of the where clause, so this can't fail.
|
// `symbol_table` must be a struct because of the where clause, so this can't fail.
|
||||||
@@ -166,5 +165,5 @@ initialize_symbols :: proc(symbol_table: ^$T, library_name: string, symbol_prefi
|
|||||||
count += 1
|
count += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return count, count > 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user