mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Merge branch 'master' into core_net_update
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
Package core:dynlib implements loading of shared libraries/DLLs and their symbols.
|
||||||
|
|
||||||
|
The behaviour of dynamically loaded libraries is specific to the target platform of the program.
|
||||||
|
For in depth detail on the underlying behaviour please refer to your target platform's documentation.
|
||||||
|
*/
|
||||||
|
package dynlib
|
||||||
+81
-2
@@ -1,15 +1,94 @@
|
|||||||
package dynlib
|
package dynlib
|
||||||
|
|
||||||
|
/*
|
||||||
|
A handle to a dynamically loaded library.
|
||||||
|
*/
|
||||||
Library :: distinct rawptr
|
Library :: distinct rawptr
|
||||||
|
|
||||||
load_library :: proc(path: string, global_symbols := false) -> (Library, bool) {
|
/*
|
||||||
|
Loads a dynamic library from the filesystem. The paramater `global_symbols` makes the symbols in the loaded
|
||||||
|
library available to resolve references in subsequently loaded libraries.
|
||||||
|
|
||||||
|
The paramater `global_symbols` is only used for the platforms `linux`, `darwin`, `freebsd` and `openbsd`.
|
||||||
|
On `windows` this paramater is ignored.
|
||||||
|
|
||||||
|
The underlying behaviour is platform specific.
|
||||||
|
On `linux`, `darwin`, `freebsd` and `openbsd` refer to `dlopen`.
|
||||||
|
On `windows` refer to `LoadLibraryW`.
|
||||||
|
|
||||||
|
**Implicit Allocators**
|
||||||
|
`context.temp_allocator`
|
||||||
|
|
||||||
|
Example:
|
||||||
|
import "core:dynlib"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
|
load_my_library :: proc() {
|
||||||
|
LIBRARY_PATH :: "my_library.dll"
|
||||||
|
library, ok := dynlib.load_library(LIBRARY_PATH)
|
||||||
|
if ! ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.println("The library %q was successfully loaded", LIBRARY_PATH)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
load_library :: proc(path: string, global_symbols := false) -> (library: Library, did_load: bool) {
|
||||||
return _load_library(path, global_symbols)
|
return _load_library(path, global_symbols)
|
||||||
}
|
}
|
||||||
|
|
||||||
unload_library :: proc(library: Library) -> bool {
|
/*
|
||||||
|
Unloads a dynamic library.
|
||||||
|
|
||||||
|
The underlying behaviour is platform specific.
|
||||||
|
On `linux`, `darwin`, `freebsd` and `openbsd` refer to `dlclose`.
|
||||||
|
On `windows` refer to `FreeLibrary`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
import "core:dynlib"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
|
load_then_unload_my_library :: proc() {
|
||||||
|
LIBRARY_PATH :: "my_library.dll"
|
||||||
|
library, ok := dynlib.load_library(LIBRARY_PATH)
|
||||||
|
if ! ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
did_unload := dynlib.unload_library(library)
|
||||||
|
if ! did_unload {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.println("The library %q was successfully unloaded", LIBRARY_PATH)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
unload_library :: proc(library: Library) -> (did_unload: bool) {
|
||||||
return _unload_library(library)
|
return _unload_library(library)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Loads the address of a procedure/variable from a dynamic library.
|
||||||
|
|
||||||
|
The underlying behaviour is platform specific.
|
||||||
|
On `linux`, `darwin`, `freebsd` and `openbsd` refer to `dlsym`.
|
||||||
|
On `windows` refer to `GetProcAddress`.
|
||||||
|
|
||||||
|
**Implicit Allocators**
|
||||||
|
`context.temp_allocator`
|
||||||
|
|
||||||
|
Example:
|
||||||
|
import "core:dynlib"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
|
find_a_in_my_library :: proc() {
|
||||||
|
LIBRARY_PATH :: "my_library.dll"
|
||||||
|
library, ok := dynlib.load_library(LIBRARY_PATH)
|
||||||
|
if ! ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
a, found_a := dynlib.symbol_address(library, "a")
|
||||||
|
if found_a do fmt.printf("The symbol %q was found at the address %v", "a", a)
|
||||||
|
}
|
||||||
|
*/
|
||||||
symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) #optional_ok {
|
symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) #optional_ok {
|
||||||
return _symbol_address(library, symbol)
|
return _symbol_address(library, symbol)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,6 +370,9 @@ foreign kernel32 {
|
|||||||
GenerateConsoleCtrlEvent :: proc(dwCtrlEvent: DWORD, dwProcessGroupId: DWORD) -> BOOL ---
|
GenerateConsoleCtrlEvent :: proc(dwCtrlEvent: DWORD, dwProcessGroupId: DWORD) -> BOOL ---
|
||||||
FreeConsole :: proc() -> BOOL ---
|
FreeConsole :: proc() -> BOOL ---
|
||||||
GetConsoleWindow :: proc() -> HWND ---
|
GetConsoleWindow :: proc() -> HWND ---
|
||||||
|
GetConsoleScreenBufferInfo :: proc(hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: PCONSOLE_SCREEN_BUFFER_INFO) -> BOOL ---
|
||||||
|
SetConsoleScreenBufferSize :: proc(hConsoleOutput: HANDLE, dwSize: COORD) -> BOOL ---
|
||||||
|
SetConsoleWindowInfo :: proc(hConsoleOutput: HANDLE, bAbsolute : BOOL, lpConsoleWindow: ^SMALL_RECT) -> BOOL ---
|
||||||
|
|
||||||
GetDiskFreeSpaceExW :: proc(
|
GetDiskFreeSpaceExW :: proc(
|
||||||
lpDirectoryName: LPCWSTR,
|
lpDirectoryName: LPCWSTR,
|
||||||
|
|||||||
@@ -3767,6 +3767,24 @@ COORD :: struct {
|
|||||||
Y: SHORT,
|
Y: SHORT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SMALL_RECT :: struct {
|
||||||
|
Left: SHORT,
|
||||||
|
Top: SHORT,
|
||||||
|
Right: SHORT,
|
||||||
|
Bottom: SHORT,
|
||||||
|
}
|
||||||
|
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO :: struct {
|
||||||
|
dwSize: COORD,
|
||||||
|
dwCursorPosition: COORD,
|
||||||
|
wAttributes: WORD,
|
||||||
|
srWindow: SMALL_RECT,
|
||||||
|
dwMaximumWindowSize: COORD,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PCONSOLE_SCREEN_BUFFER_INFO :: ^CONSOLE_SCREEN_BUFFER_INFO
|
||||||
|
|
||||||
//
|
//
|
||||||
// Networking
|
// Networking
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user