Next: , Previous: , Up: mpg-bpr   [Contents][Index]


11.3.83 foreign/[2,3]   hook

Synopsis

:- discontiguous foreign/2, foreign/3.

foreign(+Routine, +ForeignSpec)

foreign(+Routine, +Language, +ForeignSpec)

Describes the interface between Prolog and the foreign Routine. Used by load_foreign_resource/1.

Arguments

Routine

atom, must be nonvar

An atom that names a foreign code Routine.

Language

atom, must be nonvar

An atom that names the Language in which Routine is written. Can only be c.

ForeignSpec

foreign_spec, must be ground

A ground term of the form PredName(Argspec, …, Argspec) as described in Conversions between Prolog Arguments and C Types. Each Argspec should be a foreign_arg.

Description

The user has to define a foreign/[2,3] fact for every foreign function that is to be called from Prolog. Note that Routine does not have to be the same as PredicateName. Arguments are passed to the foreign function as specified in ForeignSpec.

+type

specifies that an argument is to be passed to the foreign function.

-type

specifies that an argument is to be received from the foreign function.

[-type]

argument is used to obtain the return value of a foreign function call. At most one “return value” argument can be specified.

The foreign/[2,3] facts are used only in the context of a load_foreign_resource/1 command and can be removed once the foreign files are loaded.

Contrary to most hook predicates which reside in the user module, foreign/[2,3] facts will only be looked up in the source module of the loading command.

Exceptions

Error handling is performed by load_foreign_resource/1.

See Also

load_foreign_resource/1, Calling C from Prolog.



Send feedback on this subject.