[MLton] Documentation on _export
Jens Axel Søgaard
jensaxel@soegaard.net
Fri, 23 Sep 2005 16:08:41 +0200
Matthew Fluet wrote:
> Jens Axel Søgard wrote
>> _export "C function name" attr... : cFuncTy -> unit;
>>
>> Denotes a function that must be applied to a SML function f and
>> arranges for the exported C function to call the SML function.
>> This suggests that the export happens when the denoted function
>> is called, in other words that the export happends at runtime.
>> That can't be right? What would an improved wording look like?
> I think the wording is correct. _export "foo" ensures that there is a
> symbol "foo" which may be called as a C function. However, calling the
> exported function before applying the "cFuncTy -> unit" denoted function
> to an SML function will result in an exception at runtime claiming that
> the exported function hasn't yet been initialized.
I see. The explicit explanation is thus:
_export "Cfunc" attr... : cFuncTy -> unit;
Exports a C function with the name "Cfunc" that can be used
to call an ML function of the type cFuncTy.
Before Cfunc is called from C, the function denoted by
_export "Cfunc" attr... : cFuncTy -> unit;
must be called with an SML function f whose (unfolded) type
is cFuncTy.
Is it possible to call the function denoted _export ...
twice and thus use the exported Cfunc to call different
functions at different times?
--
Jens Axel Søgaard