1if not modules then modules = { } end modules ['libs-imp-foreign'] = {
2 version = 1.001,
3 comment = "companion to luat-imp-foreign.mkxl",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9
10
11local report = logs.reporter("foreign")
12
13local libname = "foreign"
14
15local libfile = "libffi*"
16
17
18local libforeign = resolvers.libraries.validoptional(libname)
19
20if package.loaded[libname] then
21 return package.loaded[libname]
22end
23
24local function okay()
25
26
27 if not status.permit_loadlib then
28 report()
29 report("opening foreign libraries is not enabled")
30 report()
31 os.exit()
32 elseif libforeign and resolvers.libraries.optionalloaded(libname,libfile) then
33 okay = function() return true end
34 else
35 okay = function() return false end
36 end
37 return okay()
38end
39
40local foreignload = libforeign.load
41
42local foreign = {
43 types = libforeign.types,
44 abivalues = libforeign.abivalues,
45 totable = libforeign.totable,
46 newbuffer = libforeign.newbuffer,
47 getbuffer = libforeign.getbuffer,
48 load = function(name)
49 if okay() then
50 local fullname = resolvers.findlib(name)
51 if fullname and fullname ~= "" then
52 return foreignload(fullname)
53 else
54
55 end
56 end
57 end,
58}
59
60
61
62package .loaded[libname] = foreign
63optional.loaded[libname] = foreign
64
65return foreign
66 |