Exemplo n.º 1
0
func setDefaults(scope *parser.Scope) {
	scope.SetSymbol("true", parser.NewSymbol(parser.NewValueFromBool(true), true, false))
	scope.SetSymbol("false", parser.NewSymbol(parser.NewValueFromBool(false), true, false))

	scope.Modules["std"] = parser.NewModule()
	scope.Modules["std"].AddBuiltinFunctions(modules.StdFunctions)

	scope.Modules["os"] = parser.NewModule()
	scope.Modules["os"].AddBuiltinFunctions(modules.OsFunctions)

	scope.Modules["math"] = parser.NewModule()
	scope.Modules["math"].Data["pi"] = parser.NewValueFromFloat64(math.Pi)
	scope.Modules["math"].Data["e"] = parser.NewValueFromFloat64(math.E)
	scope.Modules["math"].AddBuiltinFunctions(modules.MathFunctions)

	scope.Modules["lists"] = parser.NewModule()
	scope.Modules["lists"].AddBuiltinFunctions(modules.ListFunctions)

	scope.Modules["maps"] = parser.NewModule()
	scope.Modules["maps"].AddBuiltinFunctions(modules.MapsFunctions)

	scope.Modules["files"] = parser.NewModule()
	scope.Modules["files"].AddBuiltinFunctions(modules.FilesFunctions)
	scope.Modules["files"].Data["file-separator"] = parser.NewValueFromString(string(os.PathSeparator))

	scope.Modules["strings"] = parser.NewModule()
	scope.Modules["strings"].AddBuiltinFunctions(modules.StringsFunctions)

	scope.Modules["errors"] = parser.NewModule()
	scope.Modules["errors"].AddBuiltinFunctions(modules.ErrorsFunctions)
}
Exemplo n.º 2
0
func degToRad(context *parser.FunctionCallContext) error {
	values, err := parser.ValidateArguments(context, "deg-to-rad", parser.VALUE_NUMBER)

	if err != nil {
		return err
	}

	n, _ := values[0].N.Float64()

	context.Block.Stack.Push(parser.NewValueFromFloat64((n * math.Pi) / 180))

	return nil
}
Exemplo n.º 3
0
func tan(context *parser.FunctionCallContext) error {
	values, err := parser.ValidateArguments(context, "tan", parser.VALUE_NUMBER)

	if err != nil {
		return err
	}

	n, _ := values[0].N.Float64()

	context.Block.Stack.Push(parser.NewValueFromFloat64(math.Tan(n)))

	return nil
}
Exemplo n.º 4
0
func radToDeg(context *parser.FunctionCallContext) error {
	values, err := parser.ValidateArguments(context, "rad-to-deg", parser.VALUE_NUMBER)

	if err != nil {
		return err
	}

	n, _ := values[0].N.Float64()

	context.Block.Stack.Push(parser.NewValueFromFloat64((n * 180) / math.Pi))

	return nil
}
Exemplo n.º 5
0
func pow(context *parser.FunctionCallContext) error {
	values, err := parser.ValidateArguments(context, "pow", parser.VALUE_NUMBER, parser.VALUE_NUMBER)

	if err != nil {
		return err
	}

	n1, _ := values[1].N.Float64()
	n2, _ := values[0].N.Float64()

	context.Block.Stack.Push(parser.NewValueFromFloat64(math.Pow(n1, n2)))

	return nil
}