annotate lua/luadyncall/src/dyncall.lua @ 37:8c8f848131c6

- version bump - better doc - made calling convention mode reset by default, as only way to specify convention used is via signature string
author Tassilo Philipp
date Mon, 13 Apr 2020 20:08:54 +0200
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 require "ldyncall"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 require "dynload"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 --- invoke dynamic foreign function call
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 -- This is a front-end function that provides several interfaces
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 -- @param target Target signature
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 -- @param ... if target is a string, then the arguments follow.
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 -- @see dodyncall for details
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 function dyncall(target, ...)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 local t = type(target)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 if t == "string" then
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 local libnames, sym, sig = target:match("^@(.+)/(.+)%((.+)")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 local lib = dynload(libnames) -- hold reference as long as the call
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 return ldyncall.dodyncall( dynsym( lib,sym ), sig, ...)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 else
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 return ldyncall.dodyncall( target, ...)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 end
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 end
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 -- pointer utilities
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 --
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 topointer = ldyncall.topointer
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 NULL = topointer(0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27