Skip to content

Foreign Functions

IsaacShelton edited this page Mar 21, 2022 · 1 revision

Foreign Functions

Foreign functions are functions which are implemented outside of Adept source code.

In order to access them in Adept, we have to declare their existence using the foreign keyword.

foreign sqrtf(float, float) float
foreign printf(*ubyte, ...) int
foreign atan2(double, double) double

At link time, the declared foreign function will resolve to the cdecl mangled definition with the same name.

In addition to declaring the existence of a foreign function, we must also ensure that the object file or static library containing the implementation of the foreign function is linked to when we build.

See native linking for more information.

Namespaced Foreign Functions

Namespaces do not affect the implementation name of a foreign function, however they do impact the name within Adept source code.

For example

foreign io\printf(*ubyte, ...)

is the same as

foreign printf(*ubyte, ...)

except that code written in Adept has to respect the io namespace that the foreign function is in.

Clone this wiki locally