Module "FFI": Foreign Function Interface

requireSharedLibrary \libraryName \procSignature \procName

Loads the library with the given name and looks up the procedure procName with signature procSignature in it and results in an FFI for it.

Note that procName should be a Str and procSignature should be a Symbol.

Example:

#!/usr/bin/λ -i
let puts! := requireSharedLibrary "/lib/x86_64-linux-gnu/libc.so.6" 'Cis "puts" in 
puts! "Hello world"

See the 5D Programming Manual for more details.


packRecord \format \list

Packs the given list using the given format, resulting in a Box (or Str). Note that the result can be reused later by the system. If you want to detach it, use duplicateRecord! on the result.

Possible format specifiers in the Format Str:

CharacterMeaning
bsigned byte
Bunsigned byte
hshort
Hunsigned short
iint
Iunsigned int
llong
Lunsigned long
ffloat
ddouble
glong double
ppointer
Ppointer or nil
xpadding byte (no input needed)
[array of the following

The format string can contain endian control characters. The tail of the format string starting at the endian control character will be encoded using the given endianness.

These are:

CharacterMeaning
=use machine native endian (will also align primitive fields)
>use big endian (without alignment)
<use little endian (without alignment)

Example:

packRecord "ii" [1 2] => "\x01\x00\x00\x00\x02\x00\x00\x00"

unpackRecord \format \box

Unpacks the given box using the given format, resulting in a List. See packRecord for details.

Example:

unpackRecord "ii" "\x01\x00\x00\x00\x02\x00\x00\x00" => [1 2]

allocateRecord! \format \world

Given a world, allocates an empty record with the given format, resulting in a Box (or Str) and a new World.

Example:

allocateRecord! "ii" ;\r
liftIO! r

duplicateRecord! \box \world

Given a world, duplicates the record in box, resulting in the new Box and a new World.

Example:

duplicateRecord! (packRecord "ii" [1 2]) ;\r
liftIO! r

recordSize \format

Results in the size (in bytes) a record with the given format would have.

Note that this doesn't work with record formats like [p] which have dynamic size. Just use packRecord for them.

Example:

recordSize "i" => 4