aboutsummaryrefslogtreecommitdiff
path: root/doc/ext_ffi_tutorial.html
diff options
context:
space:
mode:
authorMike Pall <mike>2022-06-23 09:10:09 +0200
committerMike Pall <mike>2022-06-23 09:10:09 +0200
commit2e98c3d0644fc0c265844908f43b7e4526dd819c (patch)
treeb9116c671f4268be7776696abdb189de4be5cf43 /doc/ext_ffi_tutorial.html
parent7dc3850e78493eed1e85fa7bc0b96068ae7fb9f4 (diff)
downloadluajit-2e98c3d0644fc0c265844908f43b7e4526dd819c.tar.gz
luajit-2e98c3d0644fc0c265844908f43b7e4526dd819c.tar.bz2
luajit-2e98c3d0644fc0c265844908f43b7e4526dd819c.zip
Grammar and spell check.
Diffstat (limited to 'doc/ext_ffi_tutorial.html')
-rw-r--r--doc/ext_ffi_tutorial.html24
1 files changed, 12 insertions, 12 deletions
diff --git a/doc/ext_ffi_tutorial.html b/doc/ext_ffi_tutorial.html
index c5e423b8..de6b6f5e 100644
--- a/doc/ext_ffi_tutorial.html
+++ b/doc/ext_ffi_tutorial.html
@@ -81,7 +81,7 @@ of its functions:
81local ffi = require("ffi") 81local ffi = require("ffi")
82</pre> 82</pre>
83<p> 83<p>
84Please note this doesn't define an <tt>ffi</tt> variable in the table 84Please note, this doesn't define an <tt>ffi</tt> variable in the table
85of globals &mdash; you really need to use the local variable. The 85of globals &mdash; you really need to use the local variable. The
86<tt>require</tt> function ensures the library is only loaded once. 86<tt>require</tt> function ensures the library is only loaded once.
87</p> 87</p>
@@ -190,7 +190,7 @@ don't need to declare them as such.
190<span class="mark">&#9316;</span> The <tt>poll()</tt> 190<span class="mark">&#9316;</span> The <tt>poll()</tt>
191function takes a couple more arguments we're not going to use. You can 191function takes a couple more arguments we're not going to use. You can
192simply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt> 192simply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt>
193for the <tt>nfds</tt> parameter. Please note that the 193for the <tt>nfds</tt> parameter. Please note, that the
194number&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>, 194number&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>,
195unlike in C++. You really have to pass pointers to pointer arguments 195unlike in C++. You really have to pass pointers to pointer arguments
196and numbers to number arguments. 196and numbers to number arguments.
@@ -287,12 +287,12 @@ Here's the step-by-step explanation:
287<p> 287<p>
288<span class="mark">&#9312;</span> This defines some of the 288<span class="mark">&#9312;</span> This defines some of the
289C&nbsp;functions provided by zlib. For the sake of this example, some 289C&nbsp;functions provided by zlib. For the sake of this example, some
290type indirections have been reduced and it uses the pre-defined 290type indirections have been reduced and it uses the predefined
291fixed-size integer types, while still adhering to the zlib API/ABI. 291fixed-size integer types, while still adhering to the zlib API/ABI.
292</p> 292</p>
293<p> 293<p>
294<span class="mark">&#9313;</span> This loads the zlib shared 294<span class="mark">&#9313;</span> This loads the zlib shared
295library. On POSIX systems it's named <tt>libz.so</tt> and usually 295library. On POSIX systems, it's named <tt>libz.so</tt> and usually
296comes pre-installed. Since <tt>ffi.load()</tt> automatically adds any 296comes pre-installed. Since <tt>ffi.load()</tt> automatically adds any
297missing standard prefixes/suffixes, we can simply load the 297missing standard prefixes/suffixes, we can simply load the
298<tt>"z"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and 298<tt>"z"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and
@@ -320,7 +320,7 @@ actual length that was used.
320<p> 320<p>
321In C you'd pass in the address of a local variable 321In C you'd pass in the address of a local variable
322(<tt>&amp;buflen</tt>). But since there's no address-of operator in 322(<tt>&amp;buflen</tt>). But since there's no address-of operator in
323Lua, we'll just pass in a one-element array. Conveniently it can be 323Lua, we'll just pass in a one-element array. Conveniently, it can be
324initialized with the maximum buffer size in one step. Calling the 324initialized with the maximum buffer size in one step. Calling the
325actual <tt>zlib.compress2</tt> function is then straightforward. 325actual <tt>zlib.compress2</tt> function is then straightforward.
326</p> 326</p>
@@ -344,7 +344,7 @@ for garbage collection and string interning.
344<span class="mark">&#9317;</span> The <tt>uncompress</tt> 344<span class="mark">&#9317;</span> The <tt>uncompress</tt>
345functions does the exact opposite of the <tt>compress</tt> function. 345functions does the exact opposite of the <tt>compress</tt> function.
346The compressed data doesn't include the size of the original string, 346The compressed data doesn't include the size of the original string,
347so this needs to be passed in. Otherwise no surprises here. 347so this needs to be passed in. Otherwise, no surprises here.
348</p> 348</p>
349<p> 349<p>
350<span class="mark">&#9318;</span> The code, that makes use 350<span class="mark">&#9318;</span> The code, that makes use
@@ -378,7 +378,7 @@ Ok, so the <tt>ffi.*</tt> functions generally accept cdata objects
378wherever you'd want to use a number. That's why we get a away with 378wherever you'd want to use a number. That's why we get a away with
379passing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua 379passing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua
380library functions or modules don't know how to deal with this. So for 380library functions or modules don't know how to deal with this. So for
381maximum portability one needs to use <tt>tonumber()</tt> on returned 381maximum portability, one needs to use <tt>tonumber()</tt> on returned
382<tt>long</tt> results before passing them on. Otherwise the 382<tt>long</tt> results before passing them on. Otherwise the
383application might work on some systems, but would fail in a POSIX/x64 383application might work on some systems, but would fail in a POSIX/x64
384environment. 384environment.
@@ -450,7 +450,7 @@ the origin.
450</p> 450</p>
451<p> 451<p>
452<span class="mark">&#9315;</span> If we run out of operators, we can 452<span class="mark">&#9315;</span> If we run out of operators, we can
453define named methods, too. Here the <tt>__index</tt> table defines an 453define named methods, too. Here, the <tt>__index</tt> table defines an
454<tt>area</tt> function. For custom indexing needs, one might want to 454<tt>area</tt> function. For custom indexing needs, one might want to
455define <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead. 455define <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead.
456</p> 456</p>
@@ -464,13 +464,13 @@ be used e.g. to create an array of points. The metamethods automatically
464apply to any and all uses of this type. 464apply to any and all uses of this type.
465</p> 465</p>
466<p> 466<p>
467Please note that the association with a metatable is permanent and 467Please note, that the association with a metatable is permanent and
468<b>the metatable must not be modified afterwards!</b> Ditto for the 468<b>the metatable must not be modified afterwards!</b> Ditto for the
469<tt>__index</tt> table. 469<tt>__index</tt> table.
470</p> 470</p>
471<p> 471<p>
472<span class="mark">&#9317;</span> Here are some simple usage examples 472<span class="mark">&#9317;</span> Here are some simple usage examples
473for the point type and their expected results. The pre-defined 473for the point type and their expected results. The predefined
474operations (such as <tt>a.x</tt>) can be freely mixed with the newly 474operations (such as <tt>a.x</tt>) can be freely mixed with the newly
475defined metamethods. Note that <tt>area</tt> is a method and must be 475defined metamethods. Note that <tt>area</tt> is a method and must be
476called with the Lua syntax for methods: <tt>a:area()</tt>, not 476called with the Lua syntax for methods: <tt>a:area()</tt>, not
@@ -479,7 +479,7 @@ called with the Lua syntax for methods: <tt>a:area()</tt>, not
479<p> 479<p>
480The C&nbsp;type metamethod mechanism is most useful when used in 480The C&nbsp;type metamethod mechanism is most useful when used in
481conjunction with C&nbsp;libraries that are written in an object-oriented 481conjunction with C&nbsp;libraries that are written in an object-oriented
482style. Creators return a pointer to a new instance and methods take an 482style. Creators return a pointer to a new instance, and methods take an
483instance pointer as the first argument. Sometimes you can just point 483instance pointer as the first argument. Sometimes you can just point
484<tt>__index</tt> to the library namespace and <tt>__gc</tt> to the 484<tt>__index</tt> to the library namespace and <tt>__gc</tt> to the
485destructor and you're done. But often enough you'll want to add 485destructor and you're done. But often enough you'll want to add
@@ -565,7 +565,7 @@ end
565</pre> 565</pre>
566<p> 566<p>
567This turns them into indirect calls and generates bigger and slower 567This turns them into indirect calls and generates bigger and slower
568machine code. Instead you'll want to cache the namespace itself and 568machine code. Instead, you'll want to cache the namespace itself and
569rely on the JIT compiler to eliminate the lookups: 569rely on the JIT compiler to eliminate the lookups:
570</p> 570</p>
571<pre class="code"> 571<pre class="code">