Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
243b768
Fix serialization format docs.
Apr 18, 2024
b8b49bf
Use generic trace error for OOM during trace stitching.
Apr 18, 2024
d2fe2a6
Show name of NYI bytecode in -jv and -jdump.
Apr 18, 2024
7110b93
OSX/iOS: Always generate 64 bit non-FAT Mach-O object files.
Apr 18, 2024
f5affaa
FFI: Turn FFI finalizer table into a proper GC root.
Apr 18, 2024
d032c63
Fix compiler warning.
Apr 18, 2024
9b5e837
Fix segment release check in internal memory allocator.
Apr 18, 2024
75e9277
Merge branch 'master' into v2.1
Apr 18, 2024
b3e4987
Windows/MSVC: Cleanup msvcbuild.bat and always generate PDB.
Apr 19, 2024
5790d25
OSX/iOS: Fix SDK incompatibility.
Apr 22, 2024
9398123
Fix internal link in docs.
May 25, 2024
a6386bd
FFI: Clarify scalar boxing behavior.
May 25, 2024
4fc48c5
Limit number of string format elements to compile.
May 25, 2024
80c1c65
Typo.
May 25, 2024
4a22050
Prevent sanitizer warning in snap_restoredata().
May 25, 2024
f5587f5
Merge branch 'master' into v2.1
May 25, 2024
93e8799
Update Nintendo Switch build script.
May 25, 2024
811c532
Handle partial snapshot restore due to stack overflow.
Jul 3, 2024
6885efb
Merge branch 'master' into v2.1
Jul 3, 2024
0f8b878
Fix typo.
Jul 3, 2024
f2a1cd4
FFI: Fix __tostring metamethod access to enum cdata value.
Jul 3, 2024
f602f01
Fix predict_next() in parser (for real now).
Jul 3, 2024
7a608e4
FFI: Fix various issues in recff_cdata_arith.
Jul 3, 2024
8038430
Merge branch 'master' into v2.1
Jul 3, 2024
747fc02
OSX: Fix installed luajit.pc.
Jul 3, 2024
444c8ff
Clarify that lj_buf_shrink() does not keep any buffer data.
Jul 3, 2024
510f88d
Add build flag LUAJIT_DISABLE_TAILCALL to disable tailcall generation.
Jul 3, 2024
7421a1b
Restore state when recording __concat metamethod throws an error.
Jul 3, 2024
04dca79
Call math.randomseed() without arguments to seed from system entropy.
Jul 3, 2024
3bdc649
Limit CSE for IR_CARG to fix loop optimizations.
Aug 14, 2024
7369eff
Fix IR_ABC hoisting.
Aug 14, 2024
86e7123
Different fix for partial snapshot restore due to stack overflow.
Aug 14, 2024
8336003
Merge branch 'master' into v2.1
Aug 14, 2024
2d54213
Add more FOLD rules for integer conversions.
Aug 14, 2024
6f83408
ARM64: Use movi to materialize FP constants.
Aug 14, 2024
ae4735f
Reflect override of INSTALL_LJLIBD in package.path.
Aug 14, 2024
19db4e9
Fix potential file descriptor leak in luaL_loadfile*().
Aug 19, 2024
5ca25ee
Correctly close VM state after early OOM during open.
Aug 19, 2024
bcc6cbb
MIPS32: Fix little-endian IR_RETF.
Aug 19, 2024
fddc965
Merge branch 'master' into v2.1
Aug 19, 2024
ab39082
Fix another potential file descriptor leak in luaL_loadfile*().
Aug 19, 2024
fb5e1c9
Merge branch 'master' into v2.1
Aug 19, 2024
fb22d0f
FFI: Drop finalizer table rehash after GC cycle.
Aug 19, 2024
32a683d
ARM: Make hard-float tobit conversions match JIT backend behavior.
Aug 20, 2024
f4fa564
Merge branch 'master' into v2.1
Aug 20, 2024
cdc2db3
ARM64: Make tobit conversions match JIT backend behavior.
Aug 20, 2024
304da39
FFI: Add missing coercion when recording 64-bit bit.*().
Aug 20, 2024
c68711c
ARM64: Use ldr literal to load FP constants.
Aug 21, 2024
9bb6b35
Always use IRT_NIL for IR_TBAR.
Aug 24, 2024
e45fd4c
Fix limit check in narrow_conv_backprop().
Aug 24, 2024
f725e44
Merge branch 'master' into v2.1
Aug 24, 2024
87ae18a
Drop unused function wrapper.
Sep 4, 2024
c63a160
Remove ancient RtlUnwindEx workaround for MinGW64.
Sep 29, 2024
5141cbc
Fix compiliation of getmetatable() for UDTYPE_IO_FILE.
Sep 29, 2024
0ae532c
Merge branch 'master' into v2.1
Sep 29, 2024
f5fd222
Fix bit op coercion in DUALNUM builds.
Sep 29, 2024
2240d84
macOS: Fix macOS 15 / Clang 16 build.
Oct 2, 2024
b2915e9
macOS: Workaround for buggy XCode 15.0 - 15.2 linker.
Oct 2, 2024
97813fb
macOS: Remove obsolete -single_module flag.
Oct 2, 2024
69bbf3c
Fix bit op coercion for shifts in DUALNUM builds.
Nov 13, 2024
9ce8f1f
Fix override of INSTALL_LJLIBD in the presence of DESTDIR.
Nov 14, 2024
fca6633
Always close profiler output file.
Nov 14, 2024
fe71d0f
Windows: Allow amalgamated static builds with msvcbuild.bat.
Nov 14, 2024
811e448
Fix detection of inconsistent renames due to sunk values.
Nov 28, 2024
4788e6f
Merge branch 'master' into v2.1
Nov 28, 2024
35a4dd6
MIPS64: Fix pcall() error case.
Nov 28, 2024
19878ec
Restore state when recording __concat metamethod throws OOM.
Nov 28, 2024
cd8d0a4
Remove dependency on <limits.h>.
Dec 16, 2024
e2e0b1d
Force fallback source name for stripped bytecode.
Dec 16, 2024
f73e649
Merge branch 'master' into v2.1
Dec 16, 2024
e823656
Bump copyright date.
Jan 13, 2025
8358eb0
Merge branch 'master' into v2.1
Jan 13, 2025
9d77734
Reject negative getfenv()/setfenv() levels to prevent compiler warning.
Jan 13, 2025
62e362a
Fix recording of BC_VARG.
Jan 13, 2025
a4f56a4
Merge branch 'master' into v2.1
Jan 13, 2025
5eb9509
Change handling of nil value markers in template tables.
Mar 9, 2025
b1179ea
Use dylib extension for iOS installs, too.
Mar 9, 2025
54dc2fa
FFI: Add pre-declared int128_t, uint128_t, __int128 types.
Mar 9, 2025
423ac21
Improve CLI signal handling on POSIX.
Mar 9, 2025
55a42da
Remove Cygwin from docs, since it's not a supported target.
Mar 9, 2025
e27ee68
Windows: Clarify installation directory layout.
Mar 9, 2025
d508715
Add compatibility string coercion for fp:seek() argument.
Mar 9, 2025
f145562
Merge branch 'master' into v2.1
Mar 9, 2025
0254770
macOS: Add suport for Apple hardened runtime.
Mar 9, 2025
4219efa
Windows: Allow mixed builds with msvcbuild.bat.
Mar 9, 2025
eee16ef
Fix state restore when recording __concat metamethod.
Mar 9, 2025
85c3f2f
Avoid unpatching bytecode twice after a trace flush.
Mar 9, 2025
e055167
Merge branch 'master' into v2.1
Mar 9, 2025
7db2d1b
Fix handling of nil value markers in template tables.
Mar 9, 2025
e3c70a7
macOS: Fix support for Apple hardened runtime.
Mar 9, 2025
4f2bb19
macOS: Fix Apple hardened runtime support and put behind build option.
Mar 10, 2025
84cb21f
REVERT: Change handling of nil value markers in template tables.
Mar 10, 2025
538a821
Change handling of nil value markers in template tables.
Mar 11, 2025
e9e4b6d
Initialize unused value when specializing to cdata metatable.
Apr 7, 2025
e76bb50
Fix error generation in load*.
Apr 7, 2025
e0a7ea8
Merge branch 'master' into v2.1
Apr 7, 2025
c262976
ARM64: Fix pass-by-value struct calling conventions.
Apr 10, 2025
51d4c26
ARM: Fix soft-float math.min()/math.max().
Apr 10, 2025
eec7a80
Prevent Clang UB 'optimization' which breaks integerness checks.
Apr 10, 2025
9c8eb7c
FFI: Fix dangling CType references.
May 28, 2025
852c3a0
Merge branch 'master' into v2.1
May 28, 2025
cd4af8a
Avoid out-of-range PC for stack overflow error from snapshot restore.
May 28, 2025
0a8cd58
Merge branch 'master' into v2.1
May 28, 2025
048972d
Fix JIT slot overflow during up-recursion.
May 28, 2025
f9140a6
Merge branch 'master' into v2.1
May 28, 2025
c64020f
FFI: Fix dangling CType references (again).
Jul 24, 2025
e3fa3c4
Avoid out-of-range PC for stack overflow error from snapshot restore.
Jul 24, 2025
c92d0cb
x86/x64: Don't use undefined MUL/IMUL zero flag.
Jul 24, 2025
eed22e9
Merge branch 'master' into v2.1
Jul 24, 2025
871db2c
Windows: Add lua52compat option to msvcbuild.bat.
Jul 24, 2025
54a1626
Fix reporting of an error during error handling.
Oct 16, 2025
a69aef4
Fix io.write() of newly created buffer.
Oct 16, 2025
a21ba1c
Add GNU/Hurd build support.
Oct 16, 2025
5c3254d
Gracefully handle broken custom allocator.
Oct 16, 2025
25a61a1
x64: Add support for CET IBT.
Oct 16, 2025
e34a78a
x64: Various fixes for CET IBT.
Oct 27, 2025
8651ef6
ARM64: Add support for ARM BTI.
Oct 28, 2025
864e78d
Windows: Fix lua52compat option for msvcbuild.bat.
Oct 28, 2025
5b20d6e
ARM64: Fix ARM BTI.
Oct 29, 2025
8518c0b
x64: Fix CET IBT.
Oct 29, 2025
3c7b158
ARM64: Fix disassembly of >2GB branch targets.
Nov 5, 2025
68354f4
Allow mcode allocations outside of the jump range to the support code.
Nov 5, 2025
578c41c
ARM64: Enable unaligned accesses if indicated by the toolchain.
Nov 8, 2025
fdf2379
macOS: Change Mach-O object file layout required by XCode 15.0.
Nov 8, 2025
5c64775
Run VM events and finalizers in separate state.
Nov 10, 2025
c94312d
FFI: Avoid dangling cts->L.
Nov 10, 2025
eba91fc
Merge branch 'master' into v2.1
Nov 10, 2025
af9763a
Fix edge cases when generating IR for string.byte/sub/find.
Nov 14, 2025
5c8cee3
Merge branch 'master' into v2.1
Nov 14, 2025
34b59f8
x86/x64: Backport fix for math.min()/math.max() argument check.
Nov 16, 2025
e274fe7
Merge branch 'master' into v2.1
Nov 16, 2025
e17ee83
ELF/Mach-O: Force default visibility for public API functions.
Nov 16, 2025
3215838
ARM64: Fix disassembly of certain sub-word-size loads/stores.
Nov 27, 2025
f80b349
Unify Lua number to FFI integer conversions.
Nov 27, 2025
1acb204
Remove compiler flag for FP conversions. Now unnecessary.
Nov 27, 2025
6b35217
Back out MSVC LJ_CONSTF declaration.
Nov 27, 2025
b973c62
Fix MSVC LJ_CONSTF declaration.
Nov 27, 2025
6f21cb8
Remove pointless GCC/MSVC const function attributes.
Dec 1, 2025
406cf69
DUALNUM: Add missing type conversion for FORI slots.
Dec 6, 2025
53d014f
Merge branch 'master' into v2.1
Dec 6, 2025
b1cd2f8
DUALNUM: Fix narrowing of unary minus.
Dec 6, 2025
c7c74ea
ARM64: More fixes for ARM BTI.
Dec 6, 2025
45b771b
PPC: Fix soft-float lj_num2u64().
Dec 6, 2025
7152e15
Fix string.format for limited precision FP conversions.
Dec 8, 2025
6e69e47
Bump copyright date.
Jan 9, 2026
2c110b7
Merge branch 'master' into v2.1
Jan 9, 2026
282e1a9
Ignore PDB files for git.
Jan 9, 2026
68d807a
Merge branch 'master' into v2.1
Jan 9, 2026
221ea00
Fix minilua undefined behavior in bit.tohex.
Jan 9, 2026
3015b61
Merge branch 'master' into v2.1
Jan 9, 2026
707c12b
DUALNUM: Improve/fix edge cases of unary minus.
Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.obj
*.lib
*.exp
*.pdb
*.dll
*.exe
*.manifest
Expand Down
2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
===============================================================================
LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/

Copyright (C) 2005-2023 Mike Pall. All rights reserved.
Copyright (C) 2005-2026 Mike Pall. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# For MSVC, please follow the instructions given in src/msvcbuild.bat.
# For MinGW and Cygwin, cd to src and run make with the Makefile there.
#
# Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
# Copyright (C) 2005-2026 Mike Pall. See Copyright Notice in luajit.h
##############################################################################

MAJVER= 2
Expand All @@ -37,12 +37,13 @@ export MULTILIB= lib
DPREFIX= $(DESTDIR)$(PREFIX)
INSTALL_BIN= $(DPREFIX)/bin
INSTALL_LIB= $(DPREFIX)/$(MULTILIB)
INSTALL_SHARE= $(DPREFIX)/share
INSTALL_SHARE_= $(PREFIX)/share
INSTALL_SHARE= $(DESTDIR)$(INSTALL_SHARE_)
INSTALL_DEFINC= $(DPREFIX)/include/luajit-$(MMVERSION)
INSTALL_INC= $(INSTALL_DEFINC)

INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(MMVERSION)
INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit
export INSTALL_LJLIBD= $(INSTALL_SHARE_)/luajit-$(MMVERSION)
INSTALL_JITLIB= $(DESTDIR)$(INSTALL_LJLIBD)/jit
INSTALL_LMODD= $(INSTALL_SHARE)/lua
INSTALL_LMOD= $(INSTALL_LMODD)/$(ABIVER)
INSTALL_CMODD= $(INSTALL_LIB)/lua
Expand Down Expand Up @@ -71,7 +72,7 @@ INSTALL_PC= $(INSTALL_PKGCONFIG)/$(INSTALL_PCNAME)

INSTALL_DIRS= $(INSTALL_BIN) $(INSTALL_LIB) $(INSTALL_INC) $(INSTALL_MAN) \
$(INSTALL_PKGCONFIG) $(INSTALL_JITLIB) $(INSTALL_LMOD) $(INSTALL_CMOD)
UNINSTALL_DIRS= $(INSTALL_JITLIB) $(INSTALL_LJLIBD) $(INSTALL_INC) \
UNINSTALL_DIRS= $(INSTALL_JITLIB) $(DESTDIR)$(INSTALL_LJLIBD) $(INSTALL_INC) \
$(INSTALL_LMOD) $(INSTALL_LMODD) $(INSTALL_CMOD) $(INSTALL_CMODD)

RM= rm -f
Expand Down Expand Up @@ -109,11 +110,12 @@ else
endif
TARGET_SYS?= $(HOST_SYS)

ifeq (Darwin,$(TARGET_SYS))
ifneq (,$(filter $(TARGET_SYS),Darwin iOS))
INSTALL_SONAME= $(INSTALL_DYLIBNAME)
INSTALL_SOSHORT1= $(INSTALL_DYLIBSHORT1)
INSTALL_SOSHORT2= $(INSTALL_DYLIBSHORT2)
LDCONFIG= :
SED_PC+= -e "s| -Wl,-E||"
endif

##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.

Project Homepage: https://luajit.org/

LuaJIT is Copyright (C) 2005-2023 Mike Pall.
LuaJIT is Copyright (C) 2005-2026 Mike Pall.
LuaJIT is free software, released under the MIT license.
See full Copyright Notice in the COPYRIGHT file or in luajit.h.

Expand Down
2 changes: 1 addition & 1 deletion doc/bluequad-print.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2023 Mike Pall.
/* Copyright (C) 2004-2026 Mike Pall.
*
* You are welcome to use the general ideas of this design for your own sites.
* But please do not steal the stylesheet, the layout or the color scheme.
Expand Down
2 changes: 1 addition & 1 deletion doc/bluequad.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2023 Mike Pall.
/* Copyright (C) 2004-2026 Mike Pall.
*
* You are welcome to use the general ideas of this design for your own sites.
* But please do not steal the stylesheet, the layout or the color scheme.
Expand Down
6 changes: 3 additions & 3 deletions doc/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Contact</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -94,15 +94,15 @@ <h1>Contact</h1>
<h2>Copyright</h2>
<p>
All documentation is
Copyright &copy; 2005-2023 Mike Pall.
Copyright &copy; 2005-2026 Mike Pall.
</p>


<br class="flush">
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
10 changes: 5 additions & 5 deletions doc/ext_buffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>String Buffer Library</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -85,7 +85,7 @@ <h1>String Buffer Library</h1>
</p>
<p>
The string buffer library also includes a high-performance
<a href="serialize">serializer</a> for Lua objects.
<a href="#serialize">serializer</a> for Lua objects.
</p>

<h2 id="use">Using the String Buffer Library</h2>
Expand Down Expand Up @@ -588,9 +588,9 @@ <h3 id="serialize_format">Serialization Format Specification</h3>
tab → 0x08 // Empty table
| 0x09 h.U h*{object object} // Key/value hash
| 0x0a a.U a*object // 0-based array
| 0x0b a.U a*object h.U h*{object object} // Mixed
| 0x0b a.U h.U a*object h*{object object} // Mixed
| 0x0c a.U (a-1)*object // 1-based array
| 0x0d a.U (a-1)*object h.U h*{object object} // Mixed
| 0x0d a.U h.U (a-1)*object h*{object object} // Mixed
tab_mt → 0x0e (index-1).U tab // Metatable dict entry

int64 → 0x10 int.L // FFI int64_t
Expand Down Expand Up @@ -679,7 +679,7 @@ <h2 id="ffi_caveats">FFI caveats</h2>
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
4 changes: 2 additions & 2 deletions doc/ext_c_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Lua/C API Extensions</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -173,7 +173,7 @@ <h3 id="mode_wrapcfunc"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)</
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
4 changes: 2 additions & 2 deletions doc/ext_ffi.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>FFI Library</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -316,7 +316,7 @@ <h2 id="cdata">Motivating Example: Using C Data Structures</h2>
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
4 changes: 2 additions & 2 deletions doc/ext_ffi_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>ffi.* API Functions</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -558,7 +558,7 @@ <h2 id="literals">Extensions to the Lua Parser</h2>
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
73 changes: 53 additions & 20 deletions doc/ext_ffi_semantics.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>FFI Semantics</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -338,42 +338,44 @@ <h3 id="convert_between">Conversions between C&nbsp;types</h3>
<tr class="odd">
<td class="convin">Integer</td><td class="convop">&rarr;<sup>round</sup></td><td class="convout"><tt>double</tt>, <tt>float</tt></td></tr>
<tr class="even">
<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup> <tt>int32_t</tt> &rarr;<sup>narrow</sup></td><td class="convout"><tt>(u)int8_t</tt>, <tt>(u)int16_t</tt></td></tr>
<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup> <tt>int64_t</tt> &rarr;<sup>narrow</sup> <sup>*</sup></td><td class="convout"><tt>(u)int8_t</tt>, <tt>(u)int16_t</tt>, <tt>(u)int32_t</tt></td></tr>
<tr class="odd">
<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup></td><td class="convout"><tt>(u)int32_t</tt>, <tt>(u)int64_t</tt></td></tr>
<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup></td><td class="convout"><tt>int64_t</tt></td></tr>
<tr class="even">
<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup> uint64_t &cup; int64_t &rarr;<sup>reinterpret</sup> <sup>*</sup></td><td class="convout"><tt>uint64_t</tt></td></tr>
<tr class="odd">
<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>round</sup></td><td class="convout"><tt>float</tt>, <tt>double</tt></td></tr>
<tr class="odd separate">
<tr class="even separate">
<td class="convin">Number</td><td class="convop">n == 0 &rarr; 0, otherwise 1</td><td class="convout"><tt>bool</tt></td></tr>
<tr class="even">
<tr class="odd">
<td class="convin"><tt>bool</tt></td><td class="convop"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class="convout">Number</td></tr>
<tr class="odd separate">
<tr class="even separate">
<td class="convin">Complex number</td><td class="convop">convert real part</td><td class="convout">Number</td></tr>
<tr class="even">
<td class="convin">Number</td><td class="convop">convert real part, imag = 0</td><td class="convout">Complex number</td></tr>
<tr class="odd">
<td class="convin">Number</td><td class="convop">convert real part, imag = 0</td><td class="convout">Complex number</td></tr>
<tr class="even">
<td class="convin">Complex number</td><td class="convop">convert real and imag part</td><td class="convout">Complex number</td></tr>
<tr class="even separate">
<tr class="odd separate">
<td class="convin">Number</td><td class="convop">convert scalar and replicate</td><td class="convout">Vector</td></tr>
<tr class="odd">
<tr class="even">
<td class="convin">Vector</td><td class="convop">copy (same size)</td><td class="convout">Vector</td></tr>
<tr class="even separate">
<tr class="odd separate">
<td class="convin"><tt>struct</tt>/<tt>union</tt></td><td class="convop">take base address (compat)</td><td class="convout">Pointer</td></tr>
<tr class="odd">
<td class="convin">Array</td><td class="convop">take base address (compat)</td><td class="convout">Pointer</td></tr>
<tr class="even">
<td class="convin">Array</td><td class="convop">take base address (compat)</td><td class="convout">Pointer</td></tr>
<tr class="odd">
<td class="convin">Function</td><td class="convop">take function address</td><td class="convout">Function pointer</td></tr>
<tr class="odd separate">
<tr class="even separate">
<td class="convin">Number</td><td class="convop">convert via <tt>uintptr_t</tt> (cast)</td><td class="convout">Pointer</td></tr>
<tr class="even">
<td class="convin">Pointer</td><td class="convop">convert address (compat/cast)</td><td class="convout">Pointer</td></tr>
<tr class="odd">
<td class="convin">Pointer</td><td class="convop">convert address (cast)</td><td class="convout">Integer</td></tr>
<td class="convin">Pointer</td><td class="convop">convert address (compat/cast)</td><td class="convout">Pointer</td></tr>
<tr class="even">
<td class="convin">Pointer</td><td class="convop">convert address (cast)</td><td class="convout">Integer</td></tr>
<tr class="odd">
<td class="convin">Array</td><td class="convop">convert base address (cast)</td><td class="convout">Integer</td></tr>
<tr class="odd separate">
<tr class="even separate">
<td class="convin">Array</td><td class="convop">copy (compat)</td><td class="convout">Array</td></tr>
<tr class="even">
<tr class="odd">
<td class="convin"><tt>struct</tt>/<tt>union</tt></td><td class="convop">copy (identical type)</td><td class="convout"><tt>struct</tt>/<tt>union</tt></td></tr>
</table>
<p>
Expand All @@ -384,6 +386,24 @@ <h3 id="convert_between">Conversions between C&nbsp;types</h3>
Conversions not listed above will raise an error. E.g. it's not
possible to convert a pointer to a complex number or vice versa.
</p>
<p>
* Some conversions from <tt>double</tt> have a larger defined range to
allow for mixed-signedness conversions, which are common in C code.
E.g. initializing an <tt>int32_t</tt> field with <tt>0xffffffff</tt>
or initializing an <tt>uint32_t</tt> or <tt>uint64_t</tt> field with
<tt>-1</tt>. Under strict conversion rules, these assignments would
give undefined results, since Lua numbers are doubles. The extended
ranges make these conversions defined. Lua numbers that are even
outside that range give an architecture-specific result.
</p>
<p>
Please note that doubles do not have the precision to represent the
whole signed or unsigned 64 bit integer range. Beware of large hex
constants in particular: e.g. <tt>0xffffffffffffffff</tt> is a double
rounded up to <tt>0x1p64</tt> during parsing. This will <em>not</em>
convert to a defined 64 bit integer value. Use the 64 bit literal
syntax instead, i.e. <tt>0xffffffffffffffffULL</tt>.
</p>

<h3 id="convert_vararg">Conversions for vararg C&nbsp;function arguments</h3>
<p>
Expand Down Expand Up @@ -440,6 +460,19 @@ <h3 id="convert_vararg">Conversions for vararg C&nbsp;function arguments</h3>
conversion rule applies. A vararg C&nbsp;function expecting an integer
will see a garbled or uninitialized value.
</p>
<p>
Note: this is the only place where creating a boxed scalar number type is
actually useful. <b>Never use <tt>ffi.new("int")</tt>, <tt>ffi.new("float")</tt>
etc. anywhere else!</b>
</p>
<p style="font-size: 8pt;">
Ditto for <tt>ffi.cast()</tt>. Explicitly boxing scalars <b>does not</b>
improve performance or force <tt>int</tt> or <tt>float</tt> arithmetic! It
just adds costly boxing, unboxing and conversions steps. And it may lead
to surprise results, because
<a href="#cdata_arith">cdata arithmetic on scalar numbers</a>
is always performed on 64 bit integers.
</p>

<h2 id="init">Initializers</h2>
<p>
Expand Down Expand Up @@ -1246,7 +1279,7 @@ <h2 id="status">Current Status</h2>
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
4 changes: 2 additions & 2 deletions doc/ext_ffi_tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>FFI Tutorial</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -587,7 +587,7 @@ <h2 id="cache">To Cache or Not to Cache</h2>
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
4 changes: 2 additions & 2 deletions doc/ext_jit.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>jit.* Library</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -187,7 +187,7 @@ <h2 id="jit_util"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
4 changes: 2 additions & 2 deletions doc/ext_profiler.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Profiler</title>
<meta charset="utf-8">
<meta name="Copyright" content="Copyright (C) 2005-2023">
<meta name="Copyright" content="Copyright (C) 2005-2026">
<meta name="Language" content="en">
<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
Expand Down Expand Up @@ -349,7 +349,7 @@ <h3 id="luaJIT_profile_dumpstack"><tt>p = luaJIT_profile_dumpstack(L, fmt, depth
</div>
<div id="foot">
<hr class="hide">
Copyright &copy; 2005-2023
Copyright &copy; 2005-2026
<span class="noprint">
&middot;
<a href="contact.html">Contact</a>
Expand Down
Loading