Skip to content

Module (namespace)

Wang Renxin edited this page Mar 3, 2016 · 11 revisions

Users may add more and more scripting interfaces to MY-BASIC, it will soon cause a naming pollution issue. It's able to separate scripting interfaces to different modules (refers to "namespace" in some other programming languages).

Use mb_begin_module to begin a module with a module name, all functions registered after a module began will be put in that module; use mb_end_module to end the current module. See the sample below:

mb_begin_module(s, "naming");

mb_register_func(s, "foo", _foo); // Register "foo" in module "naming"

mb_end_module(s);

After that it's able to write naming.foo() to call the interface.

Use IMPORT @xxx to import a module, and all symbols in that module could be used without the module prefix. Eg. after import "@naming", it's able to use foo() for short.

Read the Import another file page to get information about how import another plain source code file.

Read the Customize an importer page to get information about how to customize an importer.

Clone this wiki locally