-
Notifications
You must be signed in to change notification settings - Fork 307
Variable Types
Daniel Kang edited this page Jan 18, 2019
·
9 revisions
- Int: signed 64bit integer
- String: string
- Float: 64bit floating point
- Bool: boolean
-
Char: character (
rune
in Go) -
Bytes: byte array (
[]byte
in Go) -
Array: objects array (
[]Object
in Go) -
Map: objects map with string keys (
map[string]Object
in Go) -
ImmutableMap: objects array (
map[string]Object
in Go) - Error: an error with underlying Object value of any type
- Undefined: undefined
src\dst | Int | String | Float | Bool | Char | Bytes | Array | Map | IMap | Error | Undefined |
---|---|---|---|---|---|---|---|---|---|---|---|
Int | - | strconv | int(v) | !IsFalsy() | rune(v) | X | X | X | X | X | X |
String | strconv | - | strconv | !IsFalsy() | X | []byte(s) | X | X | X | X | X |
Float | int(f) | strconv | - | !IsFalsy() | X | X | X | X | X | X | X |
Bool | 1 / 0 | "true" / "false" | X | - | X | X | X | X | X | X | X |
Char | int(c) | string(c) | X | !IsFalsy() | - | X | X | X | X | X | X |
Bytes | X | string(y) | X | !IsFalsy() | X | - | X | X | X | X | X |
Array | X | "[...]" | X | !IsFalsy() | X | X | - | X | X | X | X |
Map | X | "{...}" | X | !IsFalsy() | X | X | X | - | X | X | X |
IMap | X | "{...}" | X | !IsFalsy() | X | X | X | X | - | X | X |
Error | X | "error: ..." | X | false | X | X | X | X | X | - | X |
Undefined | X | X | X | false | X | X | X | X | X | X | - |
X: No conversion; Typed value functions for script.Variable
will return zero values.
strconv: converted using Go's conversion functions from strconv
package.
IsFalsy(): use Object.IsFalsy() function
Object.IsFalsy()
interface method is used to determine if a given value should evaluate to false
(e.g. for condition expression of if
statement).
-
Int:
n == 0
-
String:
len(s) == 0
-
Float:
isNaN(f)
-
Bool:
!b
-
Char:
c == 0
-
Bytes:
len(bytes) == 0
-
Array:
len(arr) == 0
-
Map:
len(map) == 0
-
ImmutableMap:
len(map) == 0
-
Error:
true
(Error is always falsy) -
Undefined:
true
(Error is always falsy)
-
string(x)
: tries to convertx
into string; returnsundefined
if failed -
int(x)
: tries to convertx
into int; returnsundefined
if failed -
bool(x)
: tries to convertx
into bool; returnsundefined
if failed -
float(x)
: tries to convertx
into float; returnsundefined
if failed -
char(x)
: tries to convertx
into char; returnsundefined
if failed -
bytes(x)
: tries to convertx
into bytes; returnsundefined
if failed
-
is_string(x)
: returnstrue
ifx
is string;false
otherwise -
is_int(x)
: returnstrue
ifx
is int;false
otherwise -
is_bool(x)
: returnstrue
ifx
is bool;false
otherwise -
is_float(x)
: returnstrue
ifx
is float;false
otherwise -
is_char(x)
: returnstrue
ifx
is char;false
otherwise -
is_bytes(x)
: returnstrue
ifx
is bytes;false
otherwise -
is_error(x)
: returnstrue
ifx
is error;false
otherwise -
is_undefined(x)
: returnstrue
ifx
is undefined;false
otherwise