importVariable (schema name --)
Inputs
schema: Object orRefobject whose dereferenced schema becomes the schema of the imported variable.name: Known external and local name Text.
Outputs
- None.
schema supplies only the imported local's schema. Its current value is not imported.
The builtin creates a new local named exactly name in the current scope. That local refers to external variable storage of the selected schema.
After creation, the imported name participates in normal local lookup. Bare mention, @NAME, and !NAME therefore follow the normal MPL rules for a local of the selected schema.
This builtin declares an external variable name only. It does not create a local from an existing stack object, and it does not declare an external callable name.
Behavior
namemust be known Text.- A known
NILText name is invalid. - The same
nametext becomes both the external variable name and the created local name. Separate renaming is not provided here. - Meta targets are invalid.
- The created imported local is introduced immediately into the current scope and nested inner scopes.
- The imported local is treated as unknown and unstable.
- Repeating
importVariablewith the samenamecreates another local of that name; normal newest-to-oldest lookup then selects the latest one. - The pending
privatemodifier applies to the created imported name. - The pending
overloadandvirtualmodifiers are invalid here.
Known issue: creation can emit invalid LLVM IR even when the imported variable is unused; Clang reports global variable reference must have pointer type. Use an imported accessor function for runtime access.
Example
A fully runnable positive example also requires a separately defined external variable of the requested schema. This page therefore records the creation and lookup rules instead of a standalone executable example.
See also
NAME: ...;node—Pushes a name onto the name stack and creates a local by consuming that name and one data-stack object.codeRefbuiltin(inputsSchema output options -- code)Constructs a Code schema and pushes a knownNILCode object of that schema.defbuiltin(object name --)Creates a named local or field using a known Text name.exportFunctionbuiltin(inputsSchema output options callable name --)Exports a named function built from a Block and a signature.importFunctionbuiltin(inputsSchema output options name --)Declares or imports a named function with the supplied signature and binds it in the current scope as a Code local.usebuiltin(moduleDescriptor --)Imports public names from a module path named by known Text, or imports one selected public name when the last dot after the last path separator separates the module path from that name.