Mojo struct
DLHandle
Represents a dynamically linked library that can be loaded and unloaded.
The library is loaded on initialization and unloaded by close
.
Fields
- handle (
UnsafePointer[SIMD[int8, 1], 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]
): The handle to the dynamic library.
Implemented traits
AnyType
,
Boolable
,
CollectionElement
,
CollectionElementNew
,
Copyable
,
ExplicitlyCopyable
,
Movable
Methods
__init__
__init__(inout self: Self, path: String, flags: Int = __or__(2, 256 if eq(:string target_get_field(current_target(), "os"), "linux") else 8))
Initialize a DLHandle object by loading the dynamic library at the given path.
Args:
- path (
String
): The path to the dynamic library file. - flags (
Int
): The flags to load the dynamic library.
__init__(inout self: Self, *, other: Self)
Copy the object.
Args:
- other (
Self
): The value to copy.
__bool__
__bool__(self: Self) -> Bool
Checks if the handle is valid.
Returns:
True if the DLHandle is not null and False otherwise.
check_symbol
check_symbol(self: Self, name: String) -> Bool
Check that the symbol exists in the dynamic library.
Args:
- name (
String
): The symbol to check.
Returns:
True
if the symbol exists.
close
close(inout self: Self)
Delete the DLHandle object unloading the associated dynamic library.
get_function
get_function[result_type: AnyTrivialRegType](self: Self, name: String) -> $0
Returns a handle to the function with the given name in the dynamic library.
Parameters:
- result_type (
AnyTrivialRegType
): The type of the function pointer to return.
Args:
- name (
String
): The name of the function to get the handle for.
Returns:
A handle to the function.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
😔 What went wrong?