Created
February 12, 2016 14:42
-
-
Save david50407/451b778db43e217b07fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifdef windows | |
# already required "./winapi/kernel32.cr" in prelude | |
else | |
require "./dl/lib_dl.cr" | |
end | |
# This is a frontend wrapper, | |
# using LibDL or WinApi as backend. | |
module DL | |
ifdef windows | |
@[AlwaysInline] | |
def self.open(path) | |
WinApi.load_library(path) | |
end | |
# If specifics flags, calling LoadLibraryEx instead. | |
@[AlwaysInline] | |
def self.open(path, flags = 0) | |
WinApi.load_library_ex(path, nil, flags) | |
end | |
@[AlwaysInline] | |
def self.sym(handle, name) | |
WinApi.get_proc_address(handle, name) | |
end | |
else | |
@[AlwaysInline] | |
def self.open(path, mode = LibDL::LAZY | LibDL::GLOBAL) | |
LibDL.dlopen(path, mode) | |
end | |
@[AlwaysInline] | |
def self.sym(handle, symbol) | |
LibDL.dlsym(handle, symbol) | |
end | |
@[AlwaysInline] | |
def self.addr(addr, info) | |
LibDL.dladdr(addr, info) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment