Import

From MiniScript Wiki
Revision as of 20:09, 27 April 2020 by JoeStrout (talk | contribs) (Created page with "<c>import</c> is a Mini Micro function that loads a MiniScript file from the current directory, '''/sys/lib''', '''/usr/lib''', or some path defined in env.importPaths...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

import is a Mini Micro function that loads a MiniScript file from the current directory, /sys/lib, /usr/lib, or some path defined in env.importPaths. import looks for a file with the module name plus ".ms". Any values defined by that code then become available in a map of the same name.

Examples

The following example loads a script called "mathUtil.ms" (normally found in /sys/lib), and makes it available as a map called mathUtil.

import "mathUtil"
print mathUtil.radToDeg(2*pi)  // prints 360

Some modules, like listUtil, stringUtil, and mapUtil, extend these built-in types with new methods. For example, the built-in list type does not have a .reverse method, but it does once you import "listUtil":

import "listUtil"
print [1,2,3].reverse  // prints [3, 2, 1]