-- examples/ffi.cat -- call native code through the `ffi` library. -- -- Like Python's ctypes/CDLL: load a shared object, bind a symbol with a -- signature, and call it. libffi performs the ABI-correct call. local m = ffi.load("libm.so.6") local pow = m:func("pow", "double(double,double)") print("pow(2,10) =", pow(2, 10)) local sqrt = m:func("sqrt", "double(double)") print("sqrt(144) =", sqrt(144)) local c = ffi.load("libc.so.6") local getpid = c:func("getpid", "int()") local pid = getpid() print("getpid > 0:", pid > 0) local strlen = c:func("strlen", "long(string)") print("strlen:", strlen("catscript")) local abs = c:func("abs", "int(int)") print("abs(-42) =", abs(-42))