mint.lang - Palamecia/mint GitHub Wiki

Module

load mint.lang

This module provides functions to extend the language abilities.

Enums

ExitStatus

This enum provides standard values to use with the exit keyword.

Constant Value Description
Failure 1 Unsuccessful execution of the script.
Success 0 Successful execution of the script.

Functions

Descriptions

ExitStatus.Failure

1

Unsuccessful execution of the script.

ExitStatus.Success

0

Successful execution of the script.

atError

def (callback)

Adds callback function to be called when the script crash. The function will take two parameters corresponding to the error message and the state of the call stack when crash occured as returned by backtrace.

Example:

atError(def (message, callstack) {
    print {
        'Exited with error %s\n' % message
        'The call stack is:\n'
        for let var (module, line) in callstack {
            '  Module %s, line %d\n' % (module, line)
        }
    }
})

atExit

def (callback)

Adds callback function to be called when the script exits. The function will take one parameter corresponding to the exit code.

Example:

atExit(def (code) {
    print {'Exited with code %d\n' % code}
})

backtrace

def (const threadId = none)

Returns the current backtrace as an array of iterators containing the module path and the line number. The array starts from the most recent call to the oldest. If the threadId parameter is given, the backtrace of the thread with the given id is used; otherwise the current thread is used.

createGlobal

def (name, value = none, object = none)

Creates a new global variable named name if no variable with the same name already exists.

If value is given, the variable is initialized with the given value.

If object is given, the global variable is added to the object; otherwise the variable is added to the root package. The given object must be a class, an object or a package.

Returns true if the variable was successfully created; otherwise returns false.

eval

def (src, context = none)

Executes the src string as a mint script statement. If context is a valid hash containing variables mapping, the execution context is initialized with the given variables; otherwise an empty context is created.

Returns statement result.

exec

def (src, context = none)

Executes the src string as a mint script part. If context is a valid hash containing variables mapping, the execution context is initialized with the given variables; otherwise an empty context is created.

Returns true on execution success or false on error.

globals

def (object = none)

Returns an hash containing each global variables name mapped to its value. If object is given, the variables are the public members of the given object; otherwise the variables of the root package are used.

isDefined

def (expr)

Returns true if expr is defined; otherwise returns false. This function allow to apply the defined operator to the result of an expression.

Example:

if isDefined(var = object.getOptionalValue()) {
    // use var
}

isMain

def ()

Returns true if the current module is the main module; otherwise returns false.

loadModule

def (const modulePath)

Loads the module with the path given by modulePath. Returns true if the module was successfully loaded; otherwise returns false.

locals

def (object = none)

Returns an hash containing each local variables name mapped to its value. If object is given, the variables are the public members of the given object; otherwise the variables of the current context are used.

mainModuleFilePath

def ()

Returns the file path of the main module.

mainModulePath

def ()

Returns the module path of the main module.

modulesList

def (const modulePath = none)

Returns an array of strings containing the path of each module found under the module path given by modulePath. If the given module path is a full path to a loadable module, the array will only contains the given module. If it is path to a module directory, the array will contains the path to each module found under the directory recursively. If the path is empty, the array will contains the full list of modules installed on the system.

modulesRoots

def ()

Returns an array of strings containing the path of each directory used by the load keyword to search modules.

toFilePath

def (const modulePath)

Returns the file path of the module identified by modulePath or none if the module does not exists.

toModulePath

def (const filePath)

Returns the module path of the file identified by filePath or none if the file is not a module (i.e. is not a mint script or is not located in an accessible location).

types

def (object = none)

Returns an hash containing each class name mapped to its value. If object is given, the types are the public member class of the given object; otherwise the types of the root package are used.