diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2008-11-16 22:08:15 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2008-11-16 22:08:15 +0100 |
commit | 8b2a9401a147bd0b26cd2976ae71a1022fbde8cc (patch) | |
tree | c1a1323003ee8148af5dc60bcf1b88157dd00eb8 /lib/dyncalls.nim | |
parent | 972c51086152bd45aef4eb17c099fa3472a19d04 (diff) | |
download | Nim-8b2a9401a147bd0b26cd2976ae71a1022fbde8cc.tar.gz |
version 0.7.0
Diffstat (limited to 'lib/dyncalls.nim')
-rw-r--r-- | lib/dyncalls.nim | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/lib/dyncalls.nim b/lib/dyncalls.nim index 78c3fa115..7d7ade26c 100644 --- a/lib/dyncalls.nim +++ b/lib/dyncalls.nim @@ -7,25 +7,14 @@ # distribution, for details about the copyright. # - -# # This file implements the ability to call native procs from libraries. # It is not possible to do this in a platform independant way, unfortunately. # However, the interface has been designed to take platform differences into # account and been ported to all major platforms. -# -# interface type EInvalidLibrary = object of EOS -when defined(windows) or defined(dos): - {.define: USE_DLL.} -elif defined(posix): - {.define: USE_DLOPEN.} -elif defined(mac): - {.define: USE_DYLD.} - type TLibHandle = pointer # private type TProcAddr = pointer # libary loading and loading of procs: @@ -37,15 +26,13 @@ proc nimLoadLibrary(path: string): TLibHandle {.compilerproc.} proc nimUnloadLibrary(lib: TLibHandle) {.compilerproc.} proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr {.compilerproc.} -#implementation - # this code was inspired from Lua's source code: # Lua - An Extensible Extension Language # Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil # http://www.lua.org # mailto:info@lua.org -when defined(USE_DLOPEN): +when defined(posix): # # ========================================================================= # This is an implementation based on the dlfcn interface. @@ -76,7 +63,7 @@ when defined(USE_DLOPEN): proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr = result = dlsym(lib, name) -elif defined(USE_DLL): +elif defined(windows) or defined(dos): # # ======================================================================= # Native Windows Implementation @@ -96,13 +83,13 @@ elif defined(USE_DLL): proc nimLoadLibrary(path: string): TLibHandle = result = cast[TLibHandle](winLoadLibrary(path)) - if result == nil: + if result == nil: raise newException(EInvalidLibrary, "could not load: " & path) proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr = result = GetProcAddress(cast[THINSTANCE](lib), name) -elif defined(USE_DYLD): +elif defined(mac): # # ======================================================================= # Native Mac OS X / Darwin Implementation |