Skip to content

Instantly share code, notes, and snippets.

@david50407
Created February 12, 2016 14:42
Show Gist options
  • Save david50407/451b778db43e217b07fb to your computer and use it in GitHub Desktop.
Save david50407/451b778db43e217b07fb to your computer and use it in GitHub Desktop.
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