Module dl.loader stdlib

dl.loader
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
2
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

  • Standard Library

Imported by

This section is empty.

Overview

dl.loader is an abstraction layer over dl that provides a more user-friendly API in the V way. It can be used to Dynamically Load a library during runtime in scenarios where the library to load does not have a determined path an can be located in different places.

It also provides a way to load a library from a specific path, or from a list of paths, or from a custom environment variable that contains a list of paths.

Usage:

import dl.loader

// Load a library from a list of paths
const default_paths = [
    'not-existing-dynamic-link-library'
    // 'C:\\Windows\\System32\\shell32.dll',
    'shell32',
]

fn main() {
    mut dl_loader := loader.get_or_create_dynamic_lib_loader(
        key: 'LibExample'
        env_path: 'LIB_PATH'
        paths: default_paths
    )!

    defer {
        dl_loader.unregister()
    }

    sym := dl_loader.get_sym('CommandLineToArgvW')!
    assert !isnil(sym)
}

Aliases

This section is empty.

Constants

#constant dl_no_path_issue_code

dl_no_path_issue_code  = 1

#constant dl_open_issue_code

dl_open_issue_code     = 1

#constant dl_sym_issue_code

dl_sym_issue_code      = 2

#constant dl_close_issue_code

dl_close_issue_code    = 3

#constant dl_register_issue_code

dl_register_issue_code = 4

#constant dl_no_path_issue_err

dl_no_path_issue_err   = error_with_code(dl_no_path_issue_msg, dl_no_path_issue_code)

#constant dl_open_issue_err

dl_open_issue_err      = error_with_code(dl_open_issue_msg, dl_open_issue_code)

#constant dl_sym_issue_err

dl_sym_issue_err       = error_with_code(dl_sym_issue_msg, dl_sym_issue_code)

#constant dl_close_issue_err

dl_close_issue_err     = error_with_code(dl_close_issue_msg, dl_close_issue_code)

#constant dl_register_issue_err

dl_register_issue_err  = error_with_code(dl_register_issue_msg, dl_register_issue_code)

Sum types

This section is empty.

Functions

#fn get_or_create_dynamic_lib_loader

fn get_or_create_dynamic_lib_loader(conf DynamicLibLoaderConfig) !&DynamicLibLoader

get_or_create_dynamic_lib_loader returns a DynamicLibLoader.

If the DynamicLibLoader is not registered, it creates a new DynamicLibLoader.

#fn registered_dl_loader_keys

fn registered_dl_loader_keys() []string

registered_dl_loader_keys returns the keys of registered DynamicLibLoader.

Structs

#struct DynamicLibLoader

heap
pub struct DynamicLibLoader {
pub:
	key   string
	flags int = dl.rtld_lazy
	paths []string
mut:
	handle  voidptr
	sym_map map[string]voidptr
}

DynamicLibLoader is a wrapper around dlopen, dlsym and dlclose.

#fn new_dynamic_lib_loader

fn new_dynamic_lib_loader(conf DynamicLibLoaderConfig) !&DynamicLibLoader

new_dynamic_lib_loader returns a new DynamicLibLoader.

fn (mut dl_loader &DynamicLibLoader) open() !voidptr

load loads the dynamic library.

fn (mut dl_loader &DynamicLibLoader) close() !

close closes the dynamic library.

#fn (&DynamicLibLoader) get_sym

fn (mut dl_loader &DynamicLibLoader) get_sym(name string) !voidptr

get_sym gets a symbol from the dynamic library.

#fn (&DynamicLibLoader) unregister

fn (mut dl_loader &DynamicLibLoader) unregister()

unregister unregisters the DynamicLibLoader.

#struct DynamicLibLoaderConfig

params
pub struct DynamicLibLoaderConfig {
	// flags is the flags for dlopen.
	flags int = dl.rtld_lazy
	// key is the key to register the DynamicLibLoader.
	key string
	// env_path is the environment variable name that contains the path to the dynamic library.
	env_path string
	// paths is the list of paths to the dynamic library.
	paths []string
}

DynamicLibLoaderConfig is a configuration for DynamicLibLoader.

Interfaces

This section is empty.

Enums

This section is empty.