本文整理汇总了Golang中github.com/raoulvdberge/risp/runtime.ValidateArguments函数的典型用法代码示例。如果您正苦于以下问题:Golang ValidateArguments函数的具体用法?Golang ValidateArguments怎么用?Golang ValidateArguments使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ValidateArguments函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: listPushLeft
func listPushLeft(context *runtime.FunctionCallContext) (*runtime.Value, error) {
if err := runtime.ValidateArguments(context, runtime.ListValue, runtime.AnyValue); err != nil {
return nil, err
}
context.Args[0].List = append([]*runtime.Value{context.Args[1]}, context.Args[0].List...)
return context.Args[0], nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:9,代码来源:functions.go
示例17: stringsTrim
func stringsTrim(context *runtime.FunctionCallContext) (*runtime.Value, error) {
if err := runtime.ValidateArguments(context, runtime.StringValue, runtime.StringValue); err != nil {
return nil, err
}
source := context.Args[0].Str
cutset := context.Args[1].Str
return runtime.NewStringValue(strings.Trim(source, cutset)), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:9,代码来源:functions.go
示例18: stringsRuneAt
func stringsRuneAt(context *runtime.FunctionCallContext) (*runtime.Value, error) {
if err := runtime.ValidateArguments(context, runtime.StringValue, runtime.NumberValue); err != nil {
return nil, err
}
source := context.Args[0].Str
index := context.Args[1].NumberToInt64()
return runtime.NewStringValue(string([]rune(source)[index])), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:9,代码来源:functions.go
示例19: listJoin
func listJoin(context *runtime.FunctionCallContext) (*runtime.Value, error) {
if err := runtime.ValidateArguments(context, runtime.ListValue, runtime.ListValue); err != nil {
return nil, err
}
for _, item := range context.Args[1].List {
context.Args[0].List = append(context.Args[0].List, item)
}
return context.Args[0], nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:11,代码来源:functions.go
示例20: stringsReplace
func stringsReplace(context *runtime.FunctionCallContext) (*runtime.Value, error) {
n := -1
err := runtime.ValidateArguments(context, runtime.StringValue, runtime.StringValue, runtime.StringValue, runtime.NumberValue)
if err != nil {
optionalErr := runtime.ValidateArguments(context, runtime.StringValue, runtime.StringValue, runtime.StringValue)
if optionalErr != nil {
return nil, err
}
} else {
n = int(context.Args[3].NumberToInt64())
}
source := context.Args[0].Str
search := context.Args[1].Str
replace := context.Args[2].Str
return runtime.NewStringValue(strings.Replace(source, search, replace, n)), nil
}
开发者ID:raoulvdberge,项目名称:risp,代码行数:21,代码来源:functions.go
注:本文中的github.com/raoulvdberge/risp/runtime.ValidateArguments函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论