本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}