aboutsummaryrefslogtreecommitdiff
path: root/doc/extensions.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/extensions.html')
-rw-r--r--doc/extensions.html104
1 files changed, 89 insertions, 15 deletions
diff --git a/doc/extensions.html b/doc/extensions.html
index 25d2f7fd..25764198 100644
--- a/doc/extensions.html
+++ b/doc/extensions.html
@@ -57,6 +57,8 @@ td.excinterop {
57<a href="ext_jit.html">jit.* Library</a> 57<a href="ext_jit.html">jit.* Library</a>
58</li><li> 58</li><li>
59<a href="ext_c_api.html">Lua/C API</a> 59<a href="ext_c_api.html">Lua/C API</a>
60</li><li>
61<a href="ext_profiler.html">Profiler</a>
60</li></ul> 62</li></ul>
61</li><li> 63</li><li>
62<a href="status.html">Status</a> 64<a href="status.html">Status</a>
@@ -112,6 +114,9 @@ bit.lshift bit.rshift bit.arshift bit.rol bit.ror bit.bswap
112This module is a LuaJIT built-in &mdash; you don't need to download or 114This module is a LuaJIT built-in &mdash; you don't need to download or
113install Lua BitOp. The Lua BitOp site has full documentation for all 115install Lua BitOp. The Lua BitOp site has full documentation for all
114<a href="http://bitop.luajit.org/api.html"><span class="ext">&raquo;</span>&nbsp;Lua BitOp API functions</a>. 116<a href="http://bitop.luajit.org/api.html"><span class="ext">&raquo;</span>&nbsp;Lua BitOp API functions</a>.
117The FFI adds support for
118<a href="ext_ffi_semantics.html#cdata_arith">64&nbsp;bit bitwise operations</a>,
119using the same API functions.
115</p> 120</p>
116<p> 121<p>
117Please make sure to <tt>require</tt> the module before using any of 122Please make sure to <tt>require</tt> the module before using any of
@@ -145,6 +150,11 @@ LuaJIT adds some
145<a href="ext_c_api.html">extra functions to the Lua/C API</a>. 150<a href="ext_c_api.html">extra functions to the Lua/C API</a>.
146</p> 151</p>
147 152
153<h3 id="profiler">Profiler</h3>
154<p>
155LuaJIT has an <a href="ext_profiler.html">integrated profiler</a>.
156</p>
157
148<h2 id="library">Enhanced Standard Library Functions</h2> 158<h2 id="library">Enhanced Standard Library Functions</h2>
149 159
150<h3 id="xpcall"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3> 160<h3 id="xpcall"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3>
@@ -172,7 +182,7 @@ in <tt>"-inf"</tt>.
172<h3 id="tonumber"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3> 182<h3 id="tonumber"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3>
173<p> 183<p>
174All string-to-number conversions consistently convert integer and 184All string-to-number conversions consistently convert integer and
175floating-point inputs in decimal and hexadecimal on all platforms. 185floating-point inputs in decimal, hexadecimal and binary on all platforms.
176<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous 186<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous
177problems with poor C library implementations. The builtin conversion 187problems with poor C library implementations. The builtin conversion
178function provides full precision according to the IEEE-754 standard, it 188function provides full precision according to the IEEE-754 standard, it
@@ -196,6 +206,36 @@ for dot releases (x.y.0 &rarr; x.y.1), but may change with major or
196minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign 206minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign
197bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded. 207bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.
198</p> 208</p>
209<p>
210Note: <tt>LJ_GC64</tt> mode requires a different frame layout, which implies
211a different, incompatible bytecode format for all 64 bit ports. This may be
212rectified in the future.
213</p>
214
215<h3 id="table_new"><tt>table.new(narray, nhash)</tt> allocates a pre-sized table</h3>
216<p>
217An extra library function <tt>table.new()</tt> can be made available via
218<tt>require("table.new")</tt>. This creates a pre-sized table, just like
219the C API equivalent <tt>lua_createtable()</tt>. This is useful for big
220tables if the final table size is known and automatic table resizing is
221too expensive.
222</p>
223
224<h3 id="table_clear"><tt>table.clear(tab)</tt> clears a table</h3>
225<p>
226An extra library function <tt>table.clear()</tt> can be made available
227via <tt>require("table.clear")</tt>. This clears all keys and values
228from a table, but preserves the allocated array/hash sizes. This is
229useful when a table, which is linked from multiple places, needs to be
230cleared and/or when recycling a table for use by the same context. This
231avoids managing backlinks, saves an allocation and the overhead of
232incremental array/hash part growth.
233</p>
234<p>
235Please note this function is meant for very specific situations. In most
236cases it's better to replace the (usually single) link with a new table
237and let the GC do its work.
238</p>
199 239
200<h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3> 240<h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3>
201<p> 241<p>
@@ -274,6 +314,26 @@ indexes for varargs.</li>
274<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle 314<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle
275C&nbsp;functions.</li> 315C&nbsp;functions.</li>
276<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li> 316<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li>
317<li>Lua/C API extensions:
318<tt>lua_version()</tt>
319<tt>lua_upvalueid()</tt>
320<tt>lua_upvaluejoin()</tt>
321<tt>lua_loadx()</tt>
322<tt>lua_copy()</tt>
323<tt>lua_tonumberx()</tt>
324<tt>lua_tointegerx()</tt>
325<tt>luaL_fileresult()</tt>
326<tt>luaL_execresult()</tt>
327<tt>luaL_loadfilex()</tt>
328<tt>luaL_loadbufferx()</tt>
329<tt>luaL_traceback()</tt>
330<tt>luaL_setfuncs()</tt>
331<tt>luaL_pushmodule()</tt>
332<tt>luaL_newlibtable()</tt>
333<tt>luaL_newlib()</tt>
334<tt>luaL_testudata()</tt>
335<tt>luaL_setmetatable()</tt>
336</li>
277<li>Command line option <tt>-E</tt>.</li> 337<li>Command line option <tt>-E</tt>.</li>
278<li>Command line checks <tt>__tostring</tt> for errors.</li> 338<li>Command line checks <tt>__tostring</tt> for errors.</li>
279</ul> 339</ul>
@@ -299,6 +359,8 @@ exit status.</li>
299<li><tt>debug.setmetatable()</tt> returns object.</li> 359<li><tt>debug.setmetatable()</tt> returns object.</li>
300<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li> 360<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li>
301<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li> 361<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li>
362<li><tt>package.searchers</tt>.</li>
363<li><tt>module()</tt> returns the module table.</li>
302</ul> 364</ul>
303<p> 365<p>
304Note: this provides only partial compatibility with Lua 5.2 at the 366Note: this provides only partial compatibility with Lua 5.2 at the
@@ -307,6 +369,21 @@ Lua&nbsp;5.1, which prevents implementing features that would otherwise
307break the Lua/C API and ABI (e.g. <tt>_ENV</tt>). 369break the Lua/C API and ABI (e.g. <tt>_ENV</tt>).
308</p> 370</p>
309 371
372<h2 id="lua53">Extensions from Lua 5.3</h2>
373<p>
374LuaJIT supports some extensions from Lua&nbsp;5.3:
375<ul>
376<li>Unicode escape <tt>'\u{XX...}'</tt> embeds the UTF-8 encoding in string literals.</li>
377<li>The argument table <tt>arg</tt> can be read (and modified) by <tt>LUA_INIT</tt> and <tt>-e</tt> chunks.</li>
378<li><tt>io.read()</tt> and <tt>file:read()</tt> accept formats with or without a leading <tt>*</tt>.</li>
379<li><tt>assert()</tt> accepts any type of error object.</li>
380<li><tt>table.move(a1, f, e, t [,a2])</tt>.</li>
381<li><tt>coroutine.isyieldable()</tt>.</li>
382<li>Lua/C API extensions:
383<tt>lua_isyieldable()</tt>
384</li>
385</ul>
386
310<h2 id="exceptions">C++ Exception Interoperability</h2> 387<h2 id="exceptions">C++ Exception Interoperability</h2>
311<p> 388<p>
312LuaJIT has built-in support for interoperating with C++&nbsp;exceptions. 389LuaJIT has built-in support for interoperating with C++&nbsp;exceptions.
@@ -321,25 +398,30 @@ the toolchain used to compile LuaJIT:
321</tr> 398</tr>
322<tr class="odd separate"> 399<tr class="odd separate">
323<td class="excplatform">POSIX/x64, DWARF2 unwinding</td> 400<td class="excplatform">POSIX/x64, DWARF2 unwinding</td>
324<td class="exccompiler">GCC 4.3+</td> 401<td class="exccompiler">GCC 4.3+, Clang</td>
325<td class="excinterop"><b style="color: #00a000;">Full</b></td> 402<td class="excinterop"><b style="color: #00a000;">Full</b></td>
326</tr> 403</tr>
327<tr class="even"> 404<tr class="even">
405<td class="excplatform">ARM <tt>-DLUAJIT_UNWIND_EXTERNAL</tt></td>
406<td class="exccompiler">GCC, Clang</td>
407<td class="excinterop"><b style="color: #00a000;">Full</b></td>
408</tr>
409<tr class="odd">
328<td class="excplatform">Other platforms, DWARF2 unwinding</td> 410<td class="excplatform">Other platforms, DWARF2 unwinding</td>
329<td class="exccompiler">GCC</td> 411<td class="exccompiler">GCC, Clang</td>
330<td class="excinterop"><b style="color: #c06000;">Limited</b></td> 412<td class="excinterop"><b style="color: #c06000;">Limited</b></td>
331</tr> 413</tr>
332<tr class="odd"> 414<tr class="even">
333<td class="excplatform">Windows/x64</td> 415<td class="excplatform">Windows/x64</td>
334<td class="exccompiler">MSVC or WinSDK</td> 416<td class="exccompiler">MSVC or WinSDK</td>
335<td class="excinterop"><b style="color: #00a000;">Full</b></td> 417<td class="excinterop"><b style="color: #00a000;">Full</b></td>
336</tr> 418</tr>
337<tr class="even"> 419<tr class="odd">
338<td class="excplatform">Windows/x86</td> 420<td class="excplatform">Windows/x86</td>
339<td class="exccompiler">Any</td> 421<td class="exccompiler">Any</td>
340<td class="excinterop"><b style="color: #a00000;">No</b></td> 422<td class="excinterop"><b style="color: #00a000;">Full</b></td>
341</tr> 423</tr>
342<tr class="odd"> 424<tr class="even">
343<td class="excplatform">Other platforms</td> 425<td class="excplatform">Other platforms</td>
344<td class="exccompiler">Other compilers</td> 426<td class="exccompiler">Other compilers</td>
345<td class="excinterop"><b style="color: #a00000;">No</b></td> 427<td class="excinterop"><b style="color: #a00000;">No</b></td>
@@ -388,14 +470,6 @@ C++ destructors.</li>
388<li>Lua errors <b>cannot</b> be caught on the C++ side.</li> 470<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>
389<li>Throwing Lua errors across C++ frames will <b>not</b> call 471<li>Throwing Lua errors across C++ frames will <b>not</b> call
390C++ destructors.</li> 472C++ destructors.</li>
391<li>Additionally, on Windows/x86 with SEH-based C++&nbsp;exceptions:
392it's <b>not</b> safe to throw a Lua error across any frames containing
393a C++ function with any try/catch construct or using variables with
394(implicit) destructors. This also applies to any functions which may be
395inlined in such a function. It doesn't matter whether <tt>lua_error()</tt>
396is called inside or outside of a try/catch or whether any object actually
397needs to be destroyed: the SEH chain is corrupted and this will eventually
398lead to the termination of the process.</li>
399</ul> 473</ul>
400<br class="flush"> 474<br class="flush">
401</div> 475</div>