mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 15:14:08 +00:00
FFI: Clarify scalar boxing behavior.
Prevent misunderstandings like in #1216
This commit is contained in:
parent
9398123383
commit
a6386bdabe
@ -440,6 +440,19 @@ If you don't do this, the default Lua number → <tt>double</tt>
|
||||
conversion rule applies. A vararg C 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>
|
||||
|
Loading…
Reference in New Issue
Block a user