faq.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Frequently Asked Questions (FAQ)</title>
  5. <meta charset="utf-8">
  6. <meta name="Copyright" content="Copyright (C) 2005-2022">
  7. <meta name="Language" content="en">
  8. <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
  9. <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
  10. <style type="text/css">
  11. dd { margin-left: 1.5em; }
  12. </style>
  13. </head>
  14. <body>
  15. <div id="site">
  16. <a href="https://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
  17. </div>
  18. <div id="head">
  19. <h1>Frequently Asked Questions (FAQ)</h1>
  20. </div>
  21. <div id="nav">
  22. <ul><li>
  23. <a href="luajit.html">LuaJIT</a>
  24. <ul><li>
  25. <a href="https://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
  26. </li><li>
  27. <a href="install.html">Installation</a>
  28. </li><li>
  29. <a href="running.html">Running</a>
  30. </li></ul>
  31. </li><li>
  32. <a href="extensions.html">Extensions</a>
  33. <ul><li>
  34. <a href="ext_ffi.html">FFI Library</a>
  35. <ul><li>
  36. <a href="ext_ffi_tutorial.html">FFI Tutorial</a>
  37. </li><li>
  38. <a href="ext_ffi_api.html">ffi.* API</a>
  39. </li><li>
  40. <a href="ext_ffi_semantics.html">FFI Semantics</a>
  41. </li></ul>
  42. </li><li>
  43. <a href="ext_buffer.html">String Buffers</a>
  44. </li><li>
  45. <a href="ext_jit.html">jit.* Library</a>
  46. </li><li>
  47. <a href="ext_c_api.html">Lua/C API</a>
  48. </li><li>
  49. <a href="ext_profiler.html">Profiler</a>
  50. </li></ul>
  51. </li><li>
  52. <a href="status.html">Status</a>
  53. </li><li>
  54. <a class="current" href="faq.html">FAQ</a>
  55. </li><li>
  56. <a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
  57. </li><li>
  58. <a href="https://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
  59. </li></ul>
  60. </div>
  61. <div id="main">
  62. <dl id="info">
  63. <dt>Q: Where can I learn more about LuaJIT and Lua?</dt>
  64. <dd>
  65. <ul style="padding: 0;">
  66. <li>The <a href="https://luajit.org/list.html"><span class="ext">&raquo;</span>&nbsp;LuaJIT mailing list</a> focuses on topics
  67. related to LuaJIT.</li>
  68. <li>The <a href="http://wiki.luajit.org/"><span class="ext">&raquo;</span>&nbsp;LuaJIT wiki</a> gathers community
  69. resources about LuaJIT.</li>
  70. <li>News about Lua itself can be found at the
  71. <a href="https://www.lua.org/lua-l.html"><span class="ext">&raquo;</span>&nbsp;Lua mailing list</a>.
  72. The mailing list archives are worth checking out for older postings
  73. about LuaJIT.</li>
  74. <li>The <a href="https://lua.org"><span class="ext">&raquo;</span>&nbsp;main Lua.org site</a> has complete
  75. <a href="https://www.lua.org/docs.html"><span class="ext">&raquo;</span>&nbsp;documentation</a> of the language
  76. and links to books and papers about Lua.</li>
  77. <li>The community-managed <a href="http://lua-users.org/wiki/"><span class="ext">&raquo;</span>&nbsp;Lua Wiki</a>
  78. has information about diverse topics.</li>
  79. </ul></dd>
  80. </dl>
  81. <dl id="tech">
  82. <dt>Q: Where can I learn more about the compiler technology used by LuaJIT?</dt>
  83. <dd>
  84. Please use the following Google Scholar searches to find relevant papers:<br>
  85. Search for: <a href="https://scholar.google.com/scholar?q=Trace+Compiler"><span class="ext">&raquo;</span>&nbsp;Trace Compiler</a><br>
  86. Search for: <a href="https://scholar.google.com/scholar?q=JIT+Compiler"><span class="ext">&raquo;</span>&nbsp;JIT Compiler</a><br>
  87. Search for: <a href="https://scholar.google.com/scholar?q=Dynamic+Language+Optimizations"><span class="ext">&raquo;</span>&nbsp;Dynamic Language Optimizations</a><br>
  88. Search for: <a href="https://scholar.google.com/scholar?q=SSA+Form"><span class="ext">&raquo;</span>&nbsp;SSA Form</a><br>
  89. Search for: <a href="https://scholar.google.com/scholar?q=Linear+Scan+Register+Allocation"><span class="ext">&raquo;</span>&nbsp;Linear Scan Register Allocation</a><br>
  90. Here is a list of the <a href="http://lua-users.org/lists/lua-l/2009-11/msg00089.html"><span class="ext">&raquo;</span>&nbsp;innovative features in LuaJIT</a>.<br>
  91. And, you know, reading the source is of course the only way to enlightenment.
  92. </dd>
  93. </dl>
  94. <dl id="arg">
  95. <dt>Q: Why do I get this error: "attempt to index global 'arg' (a nil value)"?<br>
  96. Q: My vararg functions fail after switching to LuaJIT!</dt>
  97. <dd>LuaJIT is compatible to the Lua 5.1 language standard. It doesn't
  98. support the implicit <tt>arg</tt> parameter for old-style vararg
  99. functions from Lua 5.0.<br>Please convert your code to the
  100. <a href="https://www.lua.org/manual/5.1/manual.html#2.5.9"><span class="ext">&raquo;</span>&nbsp;Lua 5.1
  101. vararg syntax</a>.</dd>
  102. </dl>
  103. <dl id="x87">
  104. <dt>Q: Why do I get this error: "bad FPU precision"?<br>
  105. <dt>Q: I get weird behavior after initializing Direct3D.<br>
  106. <dt>Q: Some FPU operations crash after I load a Delphi DLL.<br>
  107. </dt>
  108. <dd>
  109. DirectX/Direct3D (up to version 9) sets the x87 FPU to single-precision
  110. mode by default. This violates the Windows ABI and interferes with the
  111. operation of many programs &mdash; LuaJIT is affected, too. Please make
  112. sure you always use the <tt>D3DCREATE_FPU_PRESERVE</tt> flag when
  113. initializing Direct3D.<br>
  114. Direct3D version 10 or higher do not show this behavior anymore.
  115. Consider testing your application with older versions, too.<br>
  116. Similarly, the Borland/Delphi runtime modifies the FPU control word and
  117. enables FP exceptions. Of course, this violates the Windows ABI, too.
  118. Please check the Delphi docs for the Set8087CW method.</dd>
  119. </dl>
  120. <dl id="ctrlc">
  121. <dt>Q: Sometimes Ctrl-C fails to stop my Lua program. Why?</dt>
  122. <dd>The interrupt signal handler sets a Lua debug hook. But this is
  123. ignored by compiled code. If your program is running in a tight loop
  124. and never falls back to the interpreter, the debug hook never runs and
  125. can't throw the "interrupted!" error.<br>
  126. You have to press Ctrl-C twice to stop your program. That's similar
  127. to when it's stuck running inside a C function under the Lua interpreter.</dd>
  128. </dl>
  129. <dl id="order">
  130. <dt>Q: Table iteration with <tt>pairs()</tt> does not result in the same order?</dt>
  131. <dd>The order of table iteration is explicitly <b>undefined</b> by
  132. the Lua language standard.<br>
  133. Different Lua implementations or versions may use different orders for
  134. otherwise identical tables. Different ways of constructing a table may
  135. result in different orders, too.<br>
  136. Due to improved VM security, LuaJIT 2.1 may even use a different order
  137. on separate VM invocations or when string keys are newly interned.<br><br>
  138. If your program relies on a deterministic order, it has a bug. Rewrite it,
  139. so it doesn't rely on the key order. Or sort the table keys, if you must.</dd>
  140. </dl>
  141. <dl id="sandbox">
  142. <dt>Q: Can Lua code be safely sandboxed?</dt>
  143. <dd>
  144. Maybe for an extremely restricted subset of Lua and if you relentlessly
  145. scrutinize every single interface function you offer to the untrusted code.<br>
  146. Although Lua provides some sandboxing functionality (<tt>setfenv()</tt>, hooks),
  147. it's very hard to get this right even for the Lua core libraries. Of course,
  148. you'll need to inspect any extension library, too. And there are libraries
  149. that are inherently unsafe, e.g. the <a href="ext_ffi.html">FFI library</a>.<br>
  150. More reading material at the <a href="http://lua-users.org/wiki/SandBoxes"><span class="ext">&raquo;</span>&nbsp;Lua Wiki</a> and <a href="https://en.wikipedia.org/wiki/Sandbox_(computer_security)"><span class="ext">&raquo;</span>&nbsp;Wikipedia</a>.<br><br>
  151. Relatedly, <b>loading untrusted bytecode is not safe!</b><br>
  152. It's trivial to crash the Lua or LuaJIT VM with maliciously crafted bytecode.
  153. This is well known and there's no bytecode verification on purpose, so please
  154. don't report a bug about it. Check the <tt>mode</tt> parameter for the
  155. <tt>load*()</tt> functions to disable loading of bytecode.<br><br>
  156. <b>In general, the only promising approach is to sandbox Lua code at the
  157. process level and not the VM level.</b>
  158. </dd>
  159. </dl>
  160. <dl id="arch">
  161. <dt>Q: Lua runs everywhere. Why doesn't LuaJIT support my CPU?</dt>
  162. <dd>Because it's a compiler &mdash; it needs to generate native
  163. machine code. This means the code generator must be ported to each
  164. architecture. And the fast interpreter is written in assembler and
  165. must be ported, too. This is quite an undertaking.<br>
  166. The <a href="install.html">install documentation</a> shows the supported
  167. architectures.<br>
  168. Other architectures may follow based on sufficient user demand and
  169. market-relevance of the architecture. Sponsoring is required to develop
  170. the port itself, to integrate it and to continuously maintain it in the
  171. actively developed branches.</dd>
  172. </dl>
  173. <br class="flush">
  174. </div>
  175. <div id="foot">
  176. <hr class="hide">
  177. Copyright &copy; 2005-2022
  178. <span class="noprint">
  179. &middot;
  180. <a href="contact.html">Contact</a>
  181. </span>
  182. </div>
  183. </body>
  184. </html>