ffi: canonical static access ffi::load (module namespace)
- '::' accesses a static/class member (here the module namespace ffi), '.'/':' sends to an instance. ffi is a module, so ffi::load is the canonical form; the native now accepts the receiver passed by '::'. - example, tests and README use ffi::load; '.load' still works (compat). - 69/69 tests
This commit is contained in:
1 parent
05f31aed68
commit
4dae4ee1cd
4 files changed
+28
-10
No files matched your search
@@ -257,14 +257,18 @@ uma assinatura declarada, usando **libffi** para a chamada ABI-correta
|
||||
(é o mesmo mecanismo por trás do ctypes do Python):
|
||||
|
||||
```lua
|
||||
local m = ffi.load("libm.so.6")
|
||||
local m = ffi::load("libm.so.6")
|
||||
local pow = m:func("pow", "double(double,double)")
|
||||
print(pow(2, 10)) -- 1024
|
||||
|
||||
local c = ffi.load("libc.so.6")
|
||||
local c = ffi::load("libc.so.6")
|
||||
local strlen = c:func("strlen", "long(string)")
|
||||
```
|
||||
|
||||
`ffi` é um módulo (namespace): `::` acessa o membro estático
|
||||
(`ffi::load`), enquanto `:` envia mensagem a uma instância
|
||||
(`m:func(...)`).
|
||||
|
||||
Gramática da assinatura: `RET(ARG,ARG,...)`, com tipos `void`, `bool`,
|
||||
`char`, `int8/uint8`, `int16/uint16`, `int/long/int32/uint32`,
|
||||
`int64/uint64/longlong`, `float`, `double`, `string`, ponteiros.
|
||||
|
||||
Reference in new issue
Block a user