Skip to content

global.import

JoeStrout edited this page Oct 17, 2026 · 3 revisions

Import a MiniScript library by name, searching MS_IMPORT_PATH; stores the module under that name and returns it

Parameters

Parameter Default Value Note
libname ""

Return value

Condition Return Value
(always) map

Notes

import "foo" loads foo.ms, runs it, and stores its locals (a map) in a variable named foo in the calling scope. It also returns that map, so m = import("foo") works too, which is handy when the module name is in a variable.

On failure (library not found, a path instead of a bare name, or a compile error in the module), import returns an error value. As a bare statement, that halts the program. With the x = import(...) form, x gets the error, which you can check with isa error.

Example

import "stringUtil"   // loads stringUtil from MS_IMPORT_PATH
print "hello world".upper   // stringUtil adds .upper to strings

// The module name can come from a variable:
name = "mathUtil"
m = import(name)
if m isa error then print "Could not load " + name else print m.indexes

Clone this wiki locally