Quirrel4.41.0

modules.get_native_module_names

Defined in module "modules"
from "modules" import get_native_module_names
get_native_module_names(): any

Returns an array with a list of names of native modules.

examples/modules/get_native_module_names-basic.nut
let modules = require("modules")
let names = modules.get_native_module_names()

println("names.contains(\"modules\") =", names.contains("modules"))
Output:
names.contains("modules") = true

Return value

An array of strings, one per native module, in ascending alphabetical order.

Notes

The set of registered native modules depends on the host binary: a thin embedding registers only a few, while a host built for full scripting support registers many more. A script cannot rely on any particular name being present, with one exception: the module system registers modules and types together as part of setting itself up, so any host where require("modules") succeeds also has types.

require("quirrel.native_modules") returns the same array directly, under a reserved pseudo-filename, without needing to require modules first.

Example

examples/modules/get_native_module_names.nut
let modules = require("modules")
let names = modules.get_native_module_names()

// The set of native modules depends on the host binary, so this checks an
// invariant instead of printing the (host-specific) list: "modules" and
// "types" are always registered together by the module system itself.
local hasModules = false
local hasTypes = false
foreach (name in names) {
  if (name == "modules") hasModules = true
  else if (name == "types") hasTypes = true
}
println("typeof names =", typeof names)
println("hasModules && hasTypes =", hasModules && hasTypes)
Output:
typeof names = array
hasModules && hasTypes = true

See also

on_module_unloadRegister module unload callback. Example: on_module_unload( function(is_app_closing) {println(is_app_closing ? "Closing" : "Soft reloading")} )
reset_static_memosReset static memo expressions cache.
modulesmodule index