api.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>API Extensions</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta name="Author" content="Mike Pall">
  7. <meta name="Copyright" content="Copyright (C) 2005-2009, Mike Pall">
  8. <meta name="Language" content="en">
  9. <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
  10. <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
  11. </head>
  12. <body>
  13. <div id="site">
  14. <a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
  15. </div>
  16. <div id="head">
  17. <h1>API Extensions</h1>
  18. </div>
  19. <div id="nav">
  20. <ul><li>
  21. <a href="luajit.html">LuaJIT</a>
  22. <ul><li>
  23. <a href="install.html">Installation</a>
  24. </li><li>
  25. <a href="running.html">Running</a>
  26. </li><li>
  27. <a class="current" href="api.html">API Extensions</a>
  28. </li></ul>
  29. </li><li>
  30. <a href="status.html">Status</a>
  31. <ul><li>
  32. <a href="changes.html">Changes</a>
  33. </li></ul>
  34. </li><li>
  35. <a href="faq.html">FAQ</a>
  36. </li><li>
  37. <a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
  38. </li></ul>
  39. </div>
  40. <div id="main">
  41. <p>
  42. LuaJIT is fully upwards-compatible with Lua 5.1. It supports all
  43. <a href="http://www.lua.org/manual/5.1/manual.html#5"><span class="ext">&raquo;</span>&nbsp;standard Lua
  44. library functions</a> and the full set of
  45. <a href="http://www.lua.org/manual/5.1/manual.html#3"><span class="ext">&raquo;</span>&nbsp;Lua/C API
  46. functions</a>.
  47. </p>
  48. <p>
  49. LuaJIT is also fully ABI-compatible to Lua 5.1 at the linker/dynamic
  50. loader level. This means you can compile a C&nbsp;module against the
  51. standard Lua headers and load the same shared library from either Lua
  52. or LuaJIT.
  53. </p>
  54. <h2 id="bit"><tt>bit.*</tt> &mdash; Bitwise Operations</h2>
  55. <p>
  56. LuaJIT supports all bitwise operations as defined by
  57. <a href="http://bitop.luajit.org"><span class="ext">&raquo;</span>&nbsp;Lua BitOp</a>:
  58. </p>
  59. <pre class="code">
  60. bit.tobit bit.tohex bit.bnot bit.band bit.bor bit.bxor
  61. bit.lshift bit.rshift bit.arshift bit.rol bit.ror bit.bswap
  62. </pre>
  63. <p>
  64. This module is a LuaJIT built-in &mdash; you don't need to download or
  65. install Lua BitOp. The Lua BitOp site has full documentation for all
  66. <a href="http://bitop.luajit.org/api.html"><span class="ext">&raquo;</span>&nbsp;Lua BitOp API functions</a>.
  67. </p>
  68. <p>
  69. Please make sure to <tt>require</tt> the module before using any of
  70. its functions:
  71. </p>
  72. <pre class="code">
  73. local bit = require("bit")
  74. </pre>
  75. <p>
  76. An already installed Lua BitOp module is ignored by LuaJIT.
  77. This way you can use bit operations from both Lua and LuaJIT on a
  78. shared installation.
  79. </p>
  80. <h2 id="jit"><tt>jit.*</tt> &mdash; JIT compiler control</h2>
  81. <p>
  82. The functions in this built-in module control the behavior
  83. of the JIT compiler engine.
  84. </p>
  85. <h3 id="jit_onoff"><tt>jit.on()<br>
  86. jit.off()</tt></h3>
  87. <p>
  88. Turns the whole JIT compiler on (default) or off.
  89. </p>
  90. <p>
  91. These functions are typically used with the command line options
  92. <tt>-j on</tt> or <tt>-j off</tt>.
  93. </p>
  94. <h3 id="jit_flush"><tt>jit.flush()</tt></h3>
  95. <p>
  96. Flushes the whole cache of compiled code.
  97. </p>
  98. <h3 id="jit_flush_tr"><tt>jit.flush(tr)</tt></h3>
  99. <p>
  100. Flushes the code for the specified root trace and all of its
  101. side traces from the cache.
  102. </p>
  103. <h3 id="jit_onoff_func"><tt>jit.on(func|true [,true|false])<br>
  104. jit.off(func|true [,true|false])<br>
  105. jit.flush(func|true [,true|false])</tt></h3>
  106. <p>
  107. <tt>jit.on</tt> enables JIT compilation for a Lua function (this is
  108. the default).
  109. </p>
  110. <p>
  111. <tt>jit.off</tt> disables JIT compilation for a Lua function and
  112. flushes any already compiled code from the code cache.
  113. </p>
  114. <p>
  115. <tt>jit.flush</tt> flushes the code, but doesn't affect the
  116. enable/disable status.
  117. </p>
  118. <p>
  119. The current function, i.e. the Lua function calling this library
  120. function, can also be specified by passing <tt>true</tt> as the first
  121. argument.
  122. </p>
  123. <p>
  124. If the second argument is <tt>true</tt>, JIT compilation is also
  125. enabled, disabled or flushed recursively for all subfunctions of a
  126. function. With <tt>false</tt> only the subfunctions are affected.
  127. </p>
  128. <p>
  129. The <tt>jit.on</tt> and <tt>jit.off</tt> functions only set a flag
  130. which is checked when the function is about to be compiled. They do
  131. not trigger immediate compilation.
  132. </p>
  133. <p>
  134. Typical usage is <tt>jit.off(true, true)</tt> in the main chunk
  135. of a module to turn off JIT compilation for the whole module for
  136. debugging purposes.
  137. </p>
  138. <h3 id="jit_version"><tt>jit.version</tt></h3>
  139. <p>
  140. Contains the LuaJIT version string.
  141. </p>
  142. <h3 id="jit_version_num"><tt>jit.version_num</tt></h3>
  143. <p>
  144. Contains the version number of the LuaJIT core. Version xx.yy.zz
  145. is represented by the decimal number xxyyzz.
  146. </p>
  147. <h3 id="jit_arch"><tt>jit.arch</tt></h3>
  148. <p>
  149. Contains the target architecture name (CPU and optional ABI).
  150. </p>
  151. <h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>
  152. <p>
  153. This module provides the backend for the <tt>-O</tt> command line
  154. option.
  155. </p>
  156. <p>
  157. You can also use it programmatically, e.g.:
  158. </p>
  159. <pre class="code">
  160. jit.opt.start(2) -- same as -O2
  161. jit.opt.start("-dce")
  162. jit.opt.start("hotloop=10", "hotexit=2")
  163. </pre>
  164. <p>
  165. Unlike in LuaJIT 1.x, the module is built-in and
  166. <b>optimization is turned on by default!</b>
  167. It's no longer necessary to run <tt>require("jit.opt").start()</tt>,
  168. which was one of the ways to enable optimization.
  169. </p>
  170. <h2 id="jit_util"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>
  171. <p>
  172. This module holds functions to introspect the bytecode, generated
  173. traces, the IR and the generated machine code. The functionality
  174. provided by this module is still in flux and therefore undocumented.
  175. </p>
  176. <p>
  177. The debug modules <tt>-jbc</tt>, <tt>-jv</tt> and <tt>-jdump</tt> make
  178. extensive use of these functions. Please check out their source code,
  179. if you want to know more.
  180. </p>
  181. <br class="flush">
  182. </div>
  183. <div id="foot">
  184. <hr class="hide">
  185. Copyright &copy; 2005-2009 Mike Pall
  186. <span class="noprint">
  187. &middot;
  188. <a href="contact.html">Contact</a>
  189. </span>
  190. </div>
  191. </body>
  192. </html>