1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
if not modules then modules = { } end modules ['libs-imp-foreign'] = {
version = 1.001,
comment = "companion to luat-imp-foreign.mkxl",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
-- See libs-imp-foreign.mkxl for some comments.
local report = logs.reporter("foreign")
local libname = "foreign"
----- libfile = "libffi-7"
local libfile = "libffi*"
----- libfile = "d:/inkscape/bin/libffi-7.dll" -- libffi*
local libforeign = resolvers.libraries.validoptional(libname)
if package.loaded[libname] then
return package.loaded[libname]
end
local function okay()
-- Don't worry, when one overloads this flag the engine will abort with an
-- error message anyway, but it's less nice.
if not status.permit_loadlib then
report()
report("opening foreign libraries is not enabled")
report()
os.exit()
elseif libforeign and resolvers.libraries.optionalloaded(libname,libfile) then
okay = function() return true end
else
okay = function() return false end
end
return okay()
end
local foreignload = libforeign.load
local foreign = {
types = libforeign.types,
abivalues = libforeign.abivalues,
totable = libforeign.totable,
newbuffer = libforeign.newbuffer,
getbuffer = libforeign.getbuffer,
load = function(name)
if okay() then
local fullname = resolvers.findlib(name)
if fullname and fullname ~= "" then
return foreignload(fullname)
else
-- report an error
end
end
end,
}
-- In due time I'll add the struct and array methods using Lua 5.4 features.
package .loaded[libname] = foreign
optional.loaded[libname] = foreign
return foreign
|