当前位置: 首页>>代码示例>>Golang>>正文


Golang runtime.ValidateArguments函数代码示例

本文整理汇总了Golang中github.com/raoulvdberge/risp/runtime.ValidateArguments函数的典型用法代码示例。如果您正苦于以下问题:Golang ValidateArguments函数的具体用法?Golang ValidateArguments怎么用?Golang ValidateArguments使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ValidateArguments函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: builtinString

func builtinString(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.AnyValue); err != nil {
		return nil, err
	}

	return runtime.NewStringValue(context.Args[0].String()), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例2: stringsUpper

func stringsUpper(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.StringValue); err != nil {
		return nil, err
	}

	return runtime.NewStringValue(strings.ToUpper(context.Args[0].Str)), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例3: builtinMath

func builtinMath(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.NumberValue, runtime.NumberValue); err != nil {
		return nil, err
	}

	base := big.NewRat(0, 1)

	var callback func(*big.Rat, *big.Rat) *big.Rat

	switch context.Name {
	case "+":
		callback = base.Add
	case "-":
		callback = base.Sub
	case "*":
		callback = base.Mul
	case "/":
		if context.Args[1].Number.Cmp(base) == 0 {
			return nil, runtime.NewRuntimeError(context.Pos, "division by zero")
		}

		callback = base.Quo
	}

	return runtime.NewNumberValueFromRat(callback(context.Args[0].Number, context.Args[1].Number)), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:26,代码来源:functions.go

示例4: stringsReverse

func stringsReverse(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.StringValue); err != nil {
		return nil, err
	}

	return runtime.NewStringValue(util.ReverseString(context.Args[0].Str)), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例5: stringsContains

func stringsContains(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.StringValue, runtime.StringValue); err != nil {
		return nil, err
	}

	return runtime.BooleanValueFor(strings.Contains(context.Args[0].Str, context.Args[1].Str)), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例6: mathRad2Deg

func mathRad2Deg(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.NumberValue); err != nil {
		return nil, err
	}

	return runtime.NewNumberValueFromFloat64((context.Args[0].NumberToFloat64() * 180) / math.Pi), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例7: mathSimpleMath

func mathSimpleMath(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.NumberValue); err != nil {
		return nil, err
	}

	var callback func(float64) float64

	switch context.Name {
	case "sqrt":
		callback = math.Sqrt
	case "sin":
		callback = math.Sin
	case "cos":
		callback = math.Cos
	case "tan":
		callback = math.Tan
	case "ceil":
		callback = math.Ceil
	case "floor":
		callback = math.Floor
	case "abs":
		callback = math.Abs
	case "log":
		callback = math.Log
	case "log10":
		callback = math.Log10
	}

	return runtime.NewNumberValueFromFloat64(callback(context.Args[0].NumberToFloat64())), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:30,代码来源:functions.go

示例8: mathPow

func mathPow(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.NumberValue, runtime.NumberValue); err != nil {
		return nil, err
	}

	return runtime.NewNumberValueFromFloat64(math.Pow(context.Args[0].NumberToFloat64(), context.Args[1].NumberToFloat64())), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例9: listSize

func listSize(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.ListValue); err != nil {
		return nil, err
	}

	return runtime.NewNumberValueFromInt64(int64(len(context.Args[0].List))), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例10: mathMod

func mathMod(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.NumberValue, runtime.NumberValue); err != nil {
		return nil, err
	}

	return runtime.NewNumberValueFromInt64(context.Args[0].NumberToInt64() % context.Args[1].NumberToInt64()), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例11: stringsLength

func stringsLength(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.StringValue); err != nil {
		return nil, err
	}

	return runtime.NewNumberValueFromInt64(int64(len(context.Args[0].Str))), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例12: stringsCharacterCheck

func stringsCharacterCheck(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.StringValue); err != nil {
		return nil, err
	}

	s := context.Args[0].Str

	if len(s) != 1 {
		return nil, runtime.NewRuntimeError(context.Pos, "expected string that has 1 character, got %d character(s)", len(s))
	}

	var callback func(rune) bool

	switch context.Name {
	case "is-digit":
		callback = unicode.IsDigit
	case "is-letter":
		callback = unicode.IsLetter
	case "is-lower":
		callback = unicode.IsLower
	case "is-upper":
		callback = unicode.IsUpper
	}

	return runtime.BooleanValueFor(callback(rune(s[0]))), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:26,代码来源:functions.go

示例13: builtinNot

func builtinNot(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.BooleanValue); err != nil {
		return nil, err
	}

	return runtime.BooleanValueFor(!context.Args[0].Boolean), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例14: builtinEval

func builtinEval(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.QuotedValue); err != nil {
		return nil, err
	}

	return context.Block.EvalNode(context.Args[0].Quoted)
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go

示例15: builtinPass

func builtinPass(context *runtime.FunctionCallContext) (*runtime.Value, error) {
	if err := runtime.ValidateArguments(context, runtime.AnyValue); err != nil {
		return runtime.Nil, nil
	}

	return context.Args[0], nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:7,代码来源:functions.go


注:本文中的github.com/raoulvdberge/risp/runtime.ValidateArguments函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。