matterbridge/vendor/github.com/d5/tengo/objects/builtins.go

165 lines
2.7 KiB
Go
Raw Normal View History

package objects
// Builtins contains all default builtin functions.
2019-03-05 22:08:54 +00:00
// Use GetBuiltinFunctions instead of accessing Builtins directly.
var Builtins = []BuiltinFunction{
{
2019-03-05 22:08:54 +00:00
Name: "print",
Value: builtinPrint,
},
{
2019-03-05 22:08:54 +00:00
Name: "printf",
Value: builtinPrintf,
},
{
2019-03-05 22:08:54 +00:00
Name: "sprintf",
Value: builtinSprintf,
},
{
2019-03-05 22:08:54 +00:00
Name: "len",
Value: builtinLen,
},
{
2019-03-05 22:08:54 +00:00
Name: "copy",
Value: builtinCopy,
},
{
2019-03-05 22:08:54 +00:00
Name: "append",
Value: builtinAppend,
},
{
2019-03-05 22:08:54 +00:00
Name: "string",
Value: builtinString,
},
{
2019-03-05 22:08:54 +00:00
Name: "int",
Value: builtinInt,
},
{
2019-03-05 22:08:54 +00:00
Name: "bool",
Value: builtinBool,
},
{
2019-03-05 22:08:54 +00:00
Name: "float",
Value: builtinFloat,
},
{
2019-03-05 22:08:54 +00:00
Name: "char",
Value: builtinChar,
},
{
2019-03-05 22:08:54 +00:00
Name: "bytes",
Value: builtinBytes,
},
{
2019-03-05 22:08:54 +00:00
Name: "time",
Value: builtinTime,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_int",
Value: builtinIsInt,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_float",
Value: builtinIsFloat,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_string",
Value: builtinIsString,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_bool",
Value: builtinIsBool,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_char",
Value: builtinIsChar,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_bytes",
Value: builtinIsBytes,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_array",
Value: builtinIsArray,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_immutable_array",
Value: builtinIsImmutableArray,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_map",
Value: builtinIsMap,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_immutable_map",
Value: builtinIsImmutableMap,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_time",
Value: builtinIsTime,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_error",
Value: builtinIsError,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_undefined",
Value: builtinIsUndefined,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_function",
Value: builtinIsFunction,
},
{
2019-03-05 22:08:54 +00:00
Name: "is_callable",
Value: builtinIsCallable,
},
{
2019-03-05 22:08:54 +00:00
Name: "to_json",
Value: builtinToJSON,
},
{
2019-03-05 22:08:54 +00:00
Name: "from_json",
Value: builtinFromJSON,
},
{
2019-03-05 22:08:54 +00:00
Name: "type_name",
Value: builtinTypeName,
},
}
2019-03-05 22:08:54 +00:00
// AllBuiltinFunctionNames returns a list of all default builtin function names.
func AllBuiltinFunctionNames() []string {
var names []string
for _, bf := range Builtins {
names = append(names, bf.Name)
}
return names
}
// GetBuiltinFunctions returns a slice of builtin function objects.
// GetBuiltinFunctions removes the duplicate names, and, the returned builtin functions
// are not guaranteed to be in the same order as names.
func GetBuiltinFunctions(names ...string) []*BuiltinFunction {
include := make(map[string]bool)
for _, name := range names {
include[name] = true
}
var builtinFuncs []*BuiltinFunction
for _, bf := range Builtins {
if include[bf.Name] {
bf := bf
builtinFuncs = append(builtinFuncs, &bf)
}
}
return builtinFuncs
}
// GetAllBuiltinFunctions returns all builtin functions.
func GetAllBuiltinFunctions() []*BuiltinFunction {
return GetBuiltinFunctions(AllBuiltinFunctionNames()...)
}