Factry Historian
...
Scripting
Builtin Functions
builtin functions format returns a formatted string the first argument must be a string object see formatting docid\ ae7jtymslbgwkdjb2fyga for more details on formatting tengo a = \[1, 2, 3] s = format("foo %v", a) // s == "foo \[1, 2, 3]" len returns the number of elements if the given variable is array, string, map, or module map tengo v = \[1, 2, 3] l = len(v) // l == 3 copy creates a copy of the given variable copy function calls object copy interface method, which is expected to return a deep copy of the value it holds tengo v1 = \[1, 2, 3] v2 = v1 v3 = copy(v1) v1\[1] = 0 print(v2\[1]) // "0"; 'v1' and 'v2' referencing the same array print(v3\[1]) // "2"; 'v3' not affected by 'v1' append appends object(s) to an array (first argument) and returns a new array object (like go's append builtin ) currently, this function takes array type only tengo v = \[1] v = append(v, 2, 3) // v == \[1, 2, 3] delete deletes the element with the specified key from the map type first argument must be a map type and second argument must be a string type (like go's delete builtin except keys are always string) delete returns undefined value if successful and it mutates given map tengo v = {key "value"} delete(v, "key") // v == {} tengo v = {key "value"} delete(v, "missing") // v == {"key" "value"} tengo delete({}) // runtime error, second argument is missing delete({}, 1) // runtime error, second argument must be a string type splice deletes and/or changes the contents of a given array and returns deleted items as a new array splice is similar to js array prototype splice() except splice is a builtin function and first argument must an array first argument must be an array, and if second and third arguments are provided those must be integers otherwise runtime error is returned usage deleted items = splice(array\[, start\[, delete count\[, item1\[, item2\[, ]]]]) tengo v = \[1, 2, 3] items = splice(v, 0) // items == \[1, 2, 3], v == \[] tengo v = \[1, 2, 3] items = splice(v, 1) // items == \[2, 3], v == \[1] tengo v = \[1, 2, 3] items = splice(v, 0, 1) // items == \[1], v == \[2, 3] tengo // deleting v = \["a", "b", "c"] items = splice(v, 1, 2) // items == \["b", "c"], v == \["a"] // splice(v, 1, 3) or splice(v, 1, 99) has same effect for this example tengo // appending v = \["a", "b", "c"] items = splice(v, 3, 0, "d", "e") // items == \[], v == \["a", "b", "c", "d", "e"] tengo // replacing v = \["a", "b", "c"] items = splice(v, 2, 1, "d") // items == \["c"], v == \["a", "b", "d"] tengo // inserting v = \["a", "b", "c"] items = splice(v, 0, 0, "d", "e") // items == \[], v == \["d", "e", "a", "b", "c"] tengo // deleting and inserting v = \["a", "b", "c"] items = splice(v, 1, 1, "d", "e") // items == \["b"], v == \["a", "d", "e", "c"] type name returns the type name of an object tengo type name(1) // int type name("str") // string type name(\[1, 2, 3]) // array string tries to convert an object to string object see runtime types docid\ smonyfzo12nj6jxyy8eu4 for more details on type conversion tengo x = string(123) // x == "123" optionally it can take the second argument, which will be returned if the first argument cannot be converted to string note that the second argument does not have to be string tengo v = string(undefined, "foo") // v == "foo" v = string(undefined, false) // v == false int tries to convert an object to int object see runtime types docid\ smonyfzo12nj6jxyy8eu4 for more details on type conversion tengo v = int("123") // v == 123 optionally it can take the second argument, which will be returned if the first argument cannot be converted to int note that the second argument does not have to be int tengo v = int(undefined, 10) // v == 10 v = int(undefined, false) // v == false bool tries to convert an object to bool object see runtime types docid\ smonyfzo12nj6jxyy8eu4 for more details on type conversion tengo v = bool(1) // v == true float tries to convert an object to float object see runtime types docid\ smonyfzo12nj6jxyy8eu4 for more details on type conversion tengo v = float("19 84") // v == 19 84 optionally it can take the second argument, which will be returned if the first argument cannot be converted to float note that the second argument does not have to be float tengo v = float(undefined, 19 84) // v == 19 84 v = float(undefined, false) // v == false char tries to convert an object to char object see runtime types docid\ smonyfzo12nj6jxyy8eu4 for more details on type conversion tengo v = char(89) // v == 'y' optionally it can take the second argument, which will be returned if the first argument cannot be converted to float note that the second argument does not have to be float tengo v = char(undefined, 'x') // v == 'x' v = char(undefined, false) // v == false bytes tries to convert an object to bytes object see runtime types docid\ smonyfzo12nj6jxyy8eu4 for more details on type conversion tengo v = bytes("foo") // v == \[102 111 111] optionally it can take the second argument, which will be returned if the first argument cannot be converted to float note that the second argument does not have to be float tengo v = bytes(undefined, bytes("foo")) // v == bytes("foo") v = bytes(undefined, false) // v == false if you pass an int to bytes() function, it will create a new byte object with the given size tengo v = bytes(100) time tries to convert an object to time value tengo v = time(1257894000) // 2009 11 10 23 00 00 +0000 utc is string returns true if the object's type is string or it returns false is int returns true if the object's type is int or it returns false is bool returns true if the object's type is bool or it returns false is float returns true if the object's type is float or it returns false is char returns true if the object's type is char or it returns false is bytes returns true if the object's type is bytes or it returns false is error returns true if the object's type is error or it returns false is undefined returns true if the object's type is undefined or it returns false is function returns true if the object's type is function or closure or it returns false note that is function returns false for builtin functions and user provided callable objects is callable returns true if the object is callable (e g function, closure, builtin function, or user provided callable objects) or it returns false is array returns true if the object's type is array or it returns false is immutable array returns true if the object's type is immutable array or it returns false is map returns true if the object's type is map or it returns false is immutable map returns true if the object's type is immutable map or it returns false is iterable returns true if the object's type is iterable array, immutable array, map, immutable map, string, and bytes are iterable types in tengo is time returns true if the object's type is time or it returns false