import
is used to import bindings which are exported by another module.
import "module-name"['(' parameter1, ..., parameterN ')'] [=> varname[: type]]
import "module-name"['(' parameter1, ..., parameterN ')'] for (varname1[: type] | type1), ..., (varnameN[: type] | typeN) [=> varname[: type]]
import "module-name"['(' parameter1, ..., parameterN ')'] {
(varname1[: type] | type1)[,]
...[,]
(varnameN[: type] | typeN)[,]* => varname
}parameter = ([module-varname:] expression | require [module-varname:] varname)
import 'chai' for expect
import 'foobar.ks' for name => foo
import 'quxbaz'(foo)
import 'color' for Color => C, Space => S
// variables: C, S
import 'color.srgb'(Color: C, Space: S) {
* => T
Color => C
Space => S
}
// variables: C, S, T
// C == T.Color
// S == T.Space
import 'parser' {
func createToken
sealed class Lexer
sealed class Parser
sealed class Token
}
// functions: createToken
// classes: Lexer, Parser, Token
import 'parser' => CT {
func createToken
sealed class Lexer
sealed class Parser
sealed class Token
}
// namespace: CT
// functions: CT.createToken
// classes: CT.Lexer, CT.Parser, CT.Token
Unnamed import will generate a variable whose name will based on the module name.
import 'fs'
// variable: fs
import 'klaw-sync'
// variable: klawSync
require
is a modifier for import parameter.
import 'moduleX'(require ClassY)
kaoscript will require the class ClassY
with the same type as expected by the module moduleX
.
export
is used when creating modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import
statement.
export statement
export member1 [=> alias], ..., memberN [=> alias]
export {
statement
member [=> alias]
}
export namespace for varname1 [=> alias], ..., varnameN [=> alias]member = (varname | member.varname)
const PI = 3.14
export PI
export enum Space<String> {
RGB
SRGB
}
namespace NS {
export {
func foo() {
}
func bar() {
}
func qux() {
}
}
}
export NS for foo, bar, qux