summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luaharfbuzz/docs/examples/package_path_searcher.lua.html
blob: 9ff317b2ea03d054b44ab715a577d3a875f1ade8 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>luaharfbuzz Documentation</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>luaharfbuzz</h1>




<h2>Examples</h2>
<ul class="nowrap">
  <li><a href="../examples/core_types.lua.html">core_types.lua</a></li>
  <li><a href="../examples/custom_callbacks.lua.html">custom_callbacks.lua</a></li>
  <li><a href="../examples/harfbuzz_setup.lua.html">harfbuzz_setup.lua</a></li>
  <li><a href="../examples/ot_font_loader.lua.html">ot_font_loader.lua</a></li>
  <li><strong>package_path_searcher.lua</strong></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
  <li><a href="../index.html">harfbuzz</a></li>
</ul>

</div>

<div id="content">

    <h2>package_path_searcher.lua</h2>
<pre>
<span class="comment">-- Allows Lua modules to be loaded from package.path and package.cpath.
</span><span class="comment">--
</span><span class="comment">-- This behavior is overridden by default in LuaTeX. This module reverts the
</span><span class="comment">-- packaging searching logic to use package.path and package.cpath first,
</span><span class="comment">-- failing which it tries to use the overridden loading logic (which uses
</span><span class="comment">-- kpse).
</span><span class="comment">--
</span><span class="comment">-- Package Loading References:
</span><span class="comment">-- 1. http://www.lua.org/manual/5.2/manual.html#pdf-package.searchers
</span><span class="comment">-- 2. LuaTeX Manual, Section 3.2, Lua behavior
</span>
<span class="keyword">local</span> make_loader = <span class="keyword">function</span>(path, pos,loadfunc)
  <span class="keyword">local</span> default_loader = <span class="global">package</span>.searchers[pos]
  <span class="keyword">local</span> loader = <span class="keyword">function</span>(name)
    <span class="keyword">local</span> file = <span class="global">package</span>.searchpath(name,path)
    <span class="keyword">if</span> <span class="keyword">not</span> file <span class="keyword">then</span>
      <span class="keyword">local</span> msg = <span class="string">"\n\t[lualoader] Search failed"</span>
      <span class="keyword">local</span> ret = default_loader(name)
      <span class="keyword">if</span> <span class="global">type</span>(ret) == <span class="string">"string"</span> <span class="keyword">then</span>
        <span class="keyword">return</span> msg ..ret
        <span class="keyword">elseif</span> <span class="global">type</span>(ret) == <span class="string">"nil"</span> <span class="keyword">then</span>
          <span class="keyword">return</span> msg
        <span class="keyword">else</span>
          <span class="keyword">return</span> ret
        <span class="keyword">end</span>
      <span class="keyword">end</span>
      <span class="keyword">local</span> loader,err = loadfunc(file)
      <span class="keyword">if</span> <span class="keyword">not</span> loader <span class="keyword">then</span>
        <span class="keyword">return</span> <span class="string">"\n\t[lualoader] Loading error:\n\t"</span>..err
      <span class="keyword">end</span>
      <span class="keyword">return</span> loader
  <span class="keyword">end</span>
    <span class="global">package</span>.searchers[pos] = loader
<span class="keyword">end</span>

<span class="keyword">local</span> binary_loader = <span class="keyword">function</span>(file)
  <span class="keyword">local</span> base = file:match(<span class="string">"/([^%.]+)%.[%w]+$"</span>)
  <span class="keyword">local</span> symbol = base:gsub(<span class="string">"%."</span>,<span class="string">"_"</span>)
  <span class="keyword">return</span> <span class="global">package</span>.loadlib(file, <span class="string">"luaopen_"</span>..symbol)
<span class="keyword">end</span>

make_loader(<span class="global">package</span>.path,<span class="number">2</span>,<span class="global">loadfile</span>)
make_loader(<span class="global">package</span>.cpath,<span class="number">3</span>, binary_loader)</pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.5</a></i>
<i style="float:right;">Last updated 2016-08-31 21:59:58 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>