28 Commits

Author SHA1 Message Date
gingerBill
1f0b24b735 Remove unneeded casts 2024-02-06 17:22:13 +00:00
gingerBill
a6878fcd91 Clean up code for initialize_symbols 2024-02-06 17:20:07 +00:00
gingerBill
3e7e779abf Replace core:* to base:* where appropriate 2024-01-28 22:18:51 +00:00
Jeroen van Rijn
e8102a40d0 Add hot reload support to dynlib.initialize_symbols 2024-01-19 18:43:02 +01:00
Laytan Laats
85b71708dd dynlib: add last_error procedure 2024-01-06 02:08:11 +01:00
Jeroen van Rijn
649b5fa528 Add bool return to dynlib.initialize_symbols. 2024-01-06 02:04:09 +01:00
Jeroen van Rijn
d6a89d667d Add dynlib.initialize_symbols (#3071)
```
package example

import "core:dynlib"
import "core:fmt"

Symbols :: struct {
	// `foo_` is prefixed, so we look for the symbol `foo_add`.
	add: proc "c" (int, int) -> int,
	// We use the tag here to override the symbol to look for, namely `bar_sub`.
	sub: proc "c" (int, int) -> int `dynlib:"bar_sub"`,

	// Exported global (if exporting an i32, the type must be ^i32 because the symbol is a pointer to the export.)
	// If it's not a pointer or procedure type, we'll skip the struct field.
	hellope: ^i32,

	// Handle to free library.
	// We can have more than one of these so we can match symbols for more than one DLL with one struct.
	_my_lib_handle: dynlib.Library,
}

main :: proc() {
	sym: Symbols

	// Load symbols from `lib.dll` into Symbols struct.
	// 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.
	count := dynlib.initialize_symbols(&sym, "lib.dll", "foo_", "_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)

	if count > 0 {
		fmt.println("42 + 42 =", sym.add(42, 42))
		fmt.println("84 - 13 =", sym.sub(84, 13))
		fmt.println("hellope =", sym.hellope^)
	}
}
```
2024-01-06 01:31:27 +01:00
Rehkitzdev
e3b43b6e1c fixed dynlib wasm stub 2023-06-22 13:35:22 +02:00
Dragos Popescu
951511704d Responded to PR review. Made dynlib return false on js instead of panic 2023-03-20 21:57:51 +01:00
Dragos Popescu
adac039a2b Made most libraries panic on js targets instead of not compiling 2023-03-20 04:08:48 +01:00
gingerBill
553f338f6f Merge pull request #2360 from Lperlind/documentation/dynlib
Document core:dynlib
2023-03-02 12:07:32 +00:00
Lucas Perlind
bb72c804fb Document core:dynlib 2023-03-02 19:20:45 +11:00
gingerBill
986cba584e Add runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD where appropriate 2023-02-10 16:23:33 +00:00
gingerBill
d8e77cd738 Add #optional_ok to dynlib.symbol_address 2022-05-25 11:53:32 +01:00
gingerBill
95d4ce4aa3 Fix lib_unix.odin 2022-05-25 11:46:26 +01:00
gingerBill
acadbe050c Make core:dynlib use the private interface convention of other packages 2022-05-25 11:43:56 +01:00
Sébastien Marie
5676c9e7eb initial OpenBSD support 2022-02-25 08:49:25 +00:00
gingerBill
ca33cb990b Strip semicolons in core which were missing 2021-09-08 13:12:38 +01:00
gingerBill
251da264ed Remove unneeded semicolons from the core library 2021-08-31 22:21:13 +01:00
gingerBill
fe33a64b2e Remove #opaque usage in core library 2021-02-23 15:21:05 +00:00
gingerBill
fd453be831 Deprecate opaque in favour of #opaque in the core library 2020-12-04 18:49:39 +00:00
gingerBill
fc4fdd588e Remove usage of do in core library 2020-09-23 17:17:14 +01:00
Christian Seibold
577be4a8ae Get Odin compiling and produced exe's running on FreeBSD 2020-09-14 15:22:35 -05:00
gingerBill
6bd05ef5d7 Begin migration from sys/win32 to sys/windows 2020-06-26 19:11:34 +01:00
Scitoshi Nakayobro
d79ee7d530 Implement dynlib core library for unix/darwin; not 100% about the build tags 2019-12-30 19:09:59 -05:00
gingerBill
8ee7ee7120 Fix core library for the new procedure parameter addressing mode 2019-07-15 22:16:27 +01:00
gingerBill
a019059975 Fix -vet for demo.odin 2019-03-30 10:52:53 +00:00
gingerBill
9b4b20e8b1 package dynlib 2019-03-03 12:08:26 +00:00