diff options
author | Mike Pall <mike> | 2024-05-25 15:48:07 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2024-05-25 15:48:07 +0200 |
commit | a6386bdabed83d87e5d1746666652108b6b2682d (patch) | |
tree | ddbb170a68fe12a30d1622979b17e753ef6ab731 /doc | |
parent | 9398123383119d4ac45336fee98bd8349cfba725 (diff) | |
download | luajit-a6386bdabed83d87e5d1746666652108b6b2682d.tar.gz luajit-a6386bdabed83d87e5d1746666652108b6b2682d.tar.bz2 luajit-a6386bdabed83d87e5d1746666652108b6b2682d.zip |
FFI: Clarify scalar boxing behavior.
Prevent misunderstandings like in #1216
Diffstat (limited to 'doc')
-rw-r--r-- | doc/ext_ffi_semantics.html | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html index 5ba82a1e..b56e57a1 100644 --- a/doc/ext_ffi_semantics.html +++ b/doc/ext_ffi_semantics.html | |||
@@ -440,6 +440,19 @@ If you don't do this, the default Lua number → <tt>double</tt> | |||
440 | conversion rule applies. A vararg C function expecting an integer | 440 | conversion rule applies. A vararg C function expecting an integer |
441 | will see a garbled or uninitialized value. | 441 | will see a garbled or uninitialized value. |
442 | </p> | 442 | </p> |
443 | <p> | ||
444 | Note: this is the only place where creating a boxed scalar number type is | ||
445 | actually useful. <b>Never use <tt>ffi.new("int")</tt>, <tt>ffi.new("float")</tt> | ||
446 | etc. anywhere else!</b> | ||
447 | </p> | ||
448 | <p style="font-size: 8pt;"> | ||
449 | Ditto for <tt>ffi.cast()</tt>. Explicitly boxing scalars <b>does not</b> | ||
450 | improve performance or force <tt>int</tt> or <tt>float</tt> arithmetic! It | ||
451 | just adds costly boxing, unboxing and conversions steps. And it may lead | ||
452 | to surprise results, because | ||
453 | <a href="#cdata_arith">cdata arithmetic on scalar numbers</a> | ||
454 | is always performed on 64 bit integers. | ||
455 | </p> | ||
443 | 456 | ||
444 | <h2 id="init">Initializers</h2> | 457 | <h2 id="init">Initializers</h2> |
445 | <p> | 458 | <p> |