class Constant
Constant Value.
Implements the Result and AST inteface.
index
static functions
-
Constant\new(type, value, raw)– construct a new Constant. -
Constant\parse(type, sep)– create a capture-function (for parsing with Lpeg). -
Constant.wrap(val[, name])– wrap a Lua value. -
Constant.num(num)– create a constant number. -
Constant.str(str)– create a constant string. -
Constant.sym(sym)– create a constant symbol. -
Constant.bool(bool)– create a constant boolean. -
Constant.bang()– create a constant bang. -
Constant.meta(args)– wrap and document a value.
ast interface
-
constant\eval(scope)– evaluate this literal constant. -
constant\stringify()– stringify this literal constant. -
constant\clone(prefix)– clone this literal constant.
result interface
-
constant\dirty()– return whether this Result was changed in the current tick. -
constant\unwrap([type[, msg]])– unwrap to the Lua type. -
constant\fork()– create a mutable copy of this stream. -
constant\__call(...)– alias for unwrap. -
constant.metatype()– Result metatype.
details
static functions
-
– construct a new Constant.
parameters:
- the type name
- the Lua value to be accessed through unwrap
- the raw string that resulted in this value. Used by parsing.
-
– create a capture-function (for parsing with Lpeg).
parameters:
- the type name (one of num, sym or str)
- the seperator char (only for str)
-
– wrap a Lua value.
Attempts to guess the type and wrap a Lua value.
parameters:
- the value to wrap
- the name of this value (for error logging) (optional)
returns:
- (Constant)
- – create a constant number.
- – create a constant string.
- – create a constant symbol.
- – create a constant boolean.
-
– create a constant bang.
returns:
- (Constant)
-
– wrap and document a value.
wraps args.value using wrap, then assigns meta.
parameters:
- table with keys value and meta
returns:
- (Constant)
ast interface
-
– evaluate this literal constant.
Throws an error if type is not a literal (num, str or sym). Returns an eval-time const result for num and str. Resolves syms in scope and returns a reference to them.
parameters:
- the scope to evaluate in
returns:
- (RTNode): the evaluation result
-
– stringify this literal constant.
Throws an error if raw is not set.
returns:
- (string): the exact string this stream was parsed from
-
– clone this literal constant.
parameters:
returns:
- (SignStream): self
result interface
-
– return whether this Result was changed in the current tick.
returns:
-
– unwrap to the Lua type.
Asserts @type == type if type is given.
parameters:
- the type to check for (optional)
- message to throw if type don't match (optional)
returns:
- (any): value
-
– create a mutable copy of this stream.
Used to insulate eval-cycles from each other.
returns:
- (Constant)
-
– alias for unwrap.
parameters:
-
– Result metatype.