annotate lua/luadyncall/src/dyncall.lua @ 52:c5ca08cd3e78

- readme typos
author Tassilo Philipp
date Fri, 22 Jan 2021 15:12:34 +0100
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