importFunction (inputsSchema output options name --)

Inputs

Outputs

importFunction constructs a function signature, records the external declaration, and creates the imported function name in the current module as a usable Code local.

Names written inside inputsSchema do not create locals in the importing scope.

Input order on the data stack follows the stack-order rule of Code signatures. Stack effects use the notation defined in Objects and values.

The created imported name is not a known NIL Code object. The builtin creates or reuses a declaration only; it does not compile a Block body.

Pending overload and private modifiers apply to the imported name. A pending virtual modifier is invalid here.

Behavior

Example

importExample.mpl

"-- codeRef only builds NIL code --" printCompilerMessage
{text: 0nx;} 0 {} codeRef printStack _:;
{text: 0nx;} 0 {} codeRef known? printStack _:;

private overload {text: 0nx;} 0 {} "puts" importFunction
{text: 0nx;} 0 {} "puts" importFunction

"-- imported name immediately usable here --" printCompilerMessage
@puts printStack _:;
@puts known? printStack _:;

virtual visible: 2;

test.mpl

"importExample.visible" use

{} 0 {} [
  "-- selected public name --" printCompilerMessage
  visible printStack _:;

  "-- private overload imported name participates in lookup --" printCompilerMessage
  @puts printStack _:;
  @puts known? printStack _:;
  0
] "main" exportFunction

Expected Output During Compilation

-- codeRef only builds NIL code --
{text: Natx;} Int32 {} codeRef CNIL
FALSE
-- imported name immediately usable here --
{text: Natx;} Int32 {} codeRef
FALSE
-- selected public name --
2
-- private overload imported name participates in lookup --
{text: Natx;} Int32 {} codeRef
FALSE

Parameter order

{fd: 0; buf: 0nx; count: 0nx;} 0ix {} "write" importFunction

{} 0 {} [
  "-- write(fd, buf, count): count is pushed first, fd is on top --" printCompilerMessage
  6nx "hello\n" storageAddress 1 write _:;
  0
] "main" exportFunction

Expected Output During Compilation

-- write(fd, buf, count): count is pushed first, fd is on top --

Expected Output

hello

See also