2019-01-09 10:17:42 +03:00
|
|
|
package objects
|
|
|
|
|
2019-01-18 20:19:45 +03:00
|
|
|
// Builtins contains all default builtin functions.
|
2019-03-01 05:41:29 +03:00
|
|
|
// Use GetBuiltinFunctions instead of accessing Builtins directly.
|
2019-02-28 19:26:25 +03:00
|
|
|
var Builtins = []BuiltinFunction{
|
2019-01-09 10:17:42 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "print",
|
|
|
|
Value: builtinPrint,
|
2019-01-09 10:17:42 +03:00
|
|
|
},
|
2019-01-25 03:38:04 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "printf",
|
|
|
|
Value: builtinPrintf,
|
2019-01-25 03:38:04 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "sprintf",
|
|
|
|
Value: builtinSprintf,
|
2019-01-25 03:38:04 +03:00
|
|
|
},
|
2019-01-09 10:17:42 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "len",
|
|
|
|
Value: builtinLen,
|
2019-01-09 10:17:42 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "copy",
|
|
|
|
Value: builtinCopy,
|
2019-01-09 10:17:42 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "append",
|
|
|
|
Value: builtinAppend,
|
2019-01-09 10:17:42 +03:00
|
|
|
},
|
2019-01-10 04:18:37 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "string",
|
|
|
|
Value: builtinString,
|
2019-01-10 04:18:37 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "int",
|
|
|
|
Value: builtinInt,
|
2019-01-10 04:18:37 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "bool",
|
|
|
|
Value: builtinBool,
|
2019-01-10 04:18:37 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "float",
|
|
|
|
Value: builtinFloat,
|
2019-01-10 04:18:37 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "char",
|
|
|
|
Value: builtinChar,
|
2019-01-10 04:18:37 +03:00
|
|
|
},
|
2019-01-18 12:43:46 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "bytes",
|
|
|
|
Value: builtinBytes,
|
2019-01-18 12:43:46 +03:00
|
|
|
},
|
2019-01-30 03:01:14 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "time",
|
|
|
|
Value: builtinTime,
|
2019-01-30 03:01:14 +03:00
|
|
|
},
|
2019-01-18 08:23:20 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_int",
|
|
|
|
Value: builtinIsInt,
|
2019-01-18 08:23:20 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_float",
|
|
|
|
Value: builtinIsFloat,
|
2019-01-18 08:23:20 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_string",
|
|
|
|
Value: builtinIsString,
|
2019-01-18 08:23:20 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_bool",
|
|
|
|
Value: builtinIsBool,
|
2019-01-18 08:23:20 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_char",
|
|
|
|
Value: builtinIsChar,
|
2019-01-18 08:23:20 +03:00
|
|
|
},
|
2019-01-18 12:43:46 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_bytes",
|
|
|
|
Value: builtinIsBytes,
|
2019-01-18 12:43:46 +03:00
|
|
|
},
|
2019-01-30 03:01:14 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_array",
|
|
|
|
Value: builtinIsArray,
|
2019-01-30 03:01:14 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_immutable_array",
|
|
|
|
Value: builtinIsImmutableArray,
|
2019-01-30 03:01:14 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_map",
|
|
|
|
Value: builtinIsMap,
|
2019-01-30 03:01:14 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_immutable_map",
|
|
|
|
Value: builtinIsImmutableMap,
|
2019-01-30 03:01:14 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_time",
|
|
|
|
Value: builtinIsTime,
|
2019-01-30 03:01:14 +03:00
|
|
|
},
|
2019-01-16 23:23:20 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_error",
|
|
|
|
Value: builtinIsError,
|
2019-01-16 23:23:20 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_undefined",
|
|
|
|
Value: builtinIsUndefined,
|
2019-01-16 23:23:20 +03:00
|
|
|
},
|
2019-02-04 02:50:40 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_function",
|
|
|
|
Value: builtinIsFunction,
|
2019-02-04 02:50:40 +03:00
|
|
|
},
|
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "is_callable",
|
|
|
|
Value: builtinIsCallable,
|
2019-02-04 02:50:40 +03:00
|
|
|
},
|
2019-01-21 13:18:53 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "to_json",
|
|
|
|
Value: builtinToJSON,
|
2019-01-21 13:18:53 +03:00
|
|
|
},
|
2019-01-21 13:24:31 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "from_json",
|
|
|
|
Value: builtinFromJSON,
|
2019-01-21 13:24:31 +03:00
|
|
|
},
|
2019-01-28 05:39:45 +03:00
|
|
|
{
|
2019-02-28 19:26:25 +03:00
|
|
|
Name: "type_name",
|
|
|
|
Value: builtinTypeName,
|
2019-01-28 05:39:45 +03:00
|
|
|
},
|
2019-01-09 10:17:42 +03:00
|
|
|
}
|
2019-03-01 05:41:29 +03: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()...)
|
|
|
|
}
|