From 2e98c3d0644fc0c265844908f43b7e4526dd819c Mon Sep 17 00:00:00 2001
From: Mike Pall
-Please note this doesn't define an ffi variable in the table
+Please note, this doesn't define an ffi variable in the table
of globals — you really need to use the local variable. The
require function ensures the library is only loaded once.
① This defines some of the
C functions provided by zlib. For the sake of this example, some
-type indirections have been reduced and it uses the pre-defined
+type indirections have been reduced and it uses the predefined
fixed-size integer types, while still adhering to the zlib API/ABI.
② This loads the zlib shared
-library. On POSIX systems it's named libz.so and usually
+library. On POSIX systems, it's named libz.so and usually
comes pre-installed. Since ffi.load() automatically adds any
missing standard prefixes/suffixes, we can simply load the
"z" library. On Windows it's named zlib1.dll and
@@ -320,7 +320,7 @@ actual length that was used.
In C you'd pass in the address of a local variable
(&buflen). But since there's no address-of operator in
-Lua, we'll just pass in a one-element array. Conveniently it can be
+Lua, we'll just pass in a one-element array. Conveniently, it can be
initialized with the maximum buffer size in one step. Calling the
actual zlib.compress2 function is then straightforward.
⑦ The code, that makes use @@ -378,7 +378,7 @@ Ok, so the ffi.* functions generally accept cdata objects wherever you'd want to use a number. That's why we get a away with passing n to ffi.string() above. But other Lua library functions or modules don't know how to deal with this. So for -maximum portability one needs to use tonumber() on returned +maximum portability, one needs to use tonumber() on returned long results before passing them on. Otherwise the application might work on some systems, but would fail in a POSIX/x64 environment. @@ -450,7 +450,7 @@ the origin.
④ If we run out of operators, we can -define named methods, too. Here the __index table defines an +define named methods, too. Here, the __index table defines an area function. For custom indexing needs, one might want to define __index and __newindex functions instead.
@@ -464,13 +464,13 @@ be used e.g. to create an array of points. The metamethods automatically apply to any and all uses of this type.-Please note that the association with a metatable is permanent and +Please note, that the association with a metatable is permanent and the metatable must not be modified afterwards! Ditto for the __index table.
⑥ Here are some simple usage examples -for the point type and their expected results. The pre-defined +for the point type and their expected results. The predefined operations (such as a.x) can be freely mixed with the newly defined metamethods. Note that area is a method and must be called with the Lua syntax for methods: a:area(), not @@ -479,7 +479,7 @@ called with the Lua syntax for methods: a:area(), not
The C type metamethod mechanism is most useful when used in conjunction with C libraries that are written in an object-oriented -style. Creators return a pointer to a new instance and methods take an +style. Creators return a pointer to a new instance, and methods take an instance pointer as the first argument. Sometimes you can just point __index to the library namespace and __gc to the destructor and you're done. But often enough you'll want to add @@ -565,7 +565,7 @@ end
This turns them into indirect calls and generates bigger and slower -machine code. Instead you'll want to cache the namespace itself and +machine code. Instead, you'll want to cache the namespace itself and rely on the JIT compiler to eliminate the lookups:
-- cgit v1.2.3-55-g6feb