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


Golang runtime.ExpectAtLeastNArgs函数代码示例

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


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

示例1: time_Date

func (t *TimeMod) time_Date(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	yr := int(args[0].Int())
	mth := 1
	if len(args) > 1 {
		mth = int(args[1].Int())
	}
	dy := 1
	if len(args) > 2 {
		dy = int(args[2].Int())
	}
	hr := 0
	if len(args) > 3 {
		hr = int(args[3].Int())
	}
	min := 0
	if len(args) > 4 {
		min = int(args[4].Int())
	}
	sec := 0
	if len(args) > 5 {
		sec = int(args[5].Int())
	}
	nsec := 0
	if len(args) > 6 {
		nsec = int(args[6].Int())
	}
	return t.newTime(time.Date(yr, time.Month(mth), dy, hr, min, sec, nsec, time.UTC))
}
开发者ID:jmptrader,项目名称:agora,代码行数:29,代码来源:time.go

示例2: os_Rename

func (o *OsMod) os_Rename(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	if e := os.Rename(args[0].String(), args[1].String()); e != nil {
		panic(e)
	}
	return runtime.Nil
}
开发者ID:jmptrader,项目名称:agora,代码行数:7,代码来源:os.go

示例3: strings_Matches

// Args:
// 0 - The string
// 1 - The regexp pattern
// 2 - (optional) a maximum number of matches to return
//
// Returns:
// An object holding all the matches, or nil if no match.
// Each match contains:
// n - The nth match group (when n=0, the full text of the match)
// Each match group contains:
// start - the index of the start of the match
// end - the end of the match
// text - the string of the match
func (s *StringsMod) strings_Matches(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	rx := regexp.MustCompile(args[1].String())
	n := -1 // By default, return all matches
	if len(args) > 2 {
		n = int(args[2].Int())
	}
	strmtch := rx.FindAllStringSubmatch(src, n)
	if strmtch == nil {
		return runtime.Nil
	}
	ixmtch := rx.FindAllStringSubmatchIndex(src, n)
	ob := runtime.NewObject()
	for i, mtches := range strmtch {
		obch := runtime.NewObject()
		for j, mtch := range mtches {
			leaf := runtime.NewObject()
			leaf.Set(runtime.String("Text"), runtime.String(mtch))
			leaf.Set(runtime.String("Start"), runtime.Number(ixmtch[i][2*j]))
			leaf.Set(runtime.String("End"), runtime.Number(ixmtch[i][2*j+1]))
			obch.Set(runtime.Number(j), leaf)
		}
		ob.Set(runtime.Number(i), obch)
	}
	return ob
}
开发者ID:jmptrader,项目名称:agora,代码行数:40,代码来源:strings.go

示例4: math_Min

func (m *MathMod) math_Min(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	min := args[len(args)-1].Float()
	for i := len(args) - 2; i >= 0; i-- {
		min = math.Min(min, args[i].Float())
	}
	return runtime.Number(min)
}
开发者ID:jmptrader,项目名称:agora,代码行数:8,代码来源:math.go

示例5: math_Max

func (m *MathMod) math_Max(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	max := args[len(args)-1].Float()
	for i := len(args) - 2; i >= 0; i-- {
		max = math.Max(max, args[i].Float())
	}
	return runtime.Number(max)
}
开发者ID:jmptrader,项目名称:agora,代码行数:8,代码来源:math.go

示例6: os_ReadFile

func (o *OsMod) os_ReadFile(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	b, e := ioutil.ReadFile(args[0].String())
	if e != nil {
		panic(e)
	}
	return runtime.String(b)
}
开发者ID:jmptrader,项目名称:agora,代码行数:8,代码来源:os.go

示例7: filepath_Abs

func (fp *FilepathMod) filepath_Abs(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	s, e := filepath.Abs(args[0].String())
	if e != nil {
		panic(e)
	}
	return runtime.String(s)
}
开发者ID:jmptrader,项目名称:agora,代码行数:8,代码来源:filepath.go

示例8: strings_ByteAt

// Args:
// 0 - The source string
// 1 - The 0-based index number
//
// Returns:
// The character at that position, as a string, or an empty string if
// the index is out of bounds.
func (s *StringsMod) strings_ByteAt(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	at := int(args[1].Int())
	if at < 0 || at >= len(src) {
		return runtime.String("")
	}
	return runtime.String(src[at])
}
开发者ID:jmptrader,项目名称:agora,代码行数:16,代码来源:strings.go

示例9: strings_Trim

// Args:
// 0 - the source string
// 1 [optional] - the cutset (all leading and trailing characters in this string will be
// removed). Defaults to whitespace (space, \n, \t, \v and \r).
// Returns:
// The trimmed string.
func (s *StringsMod) strings_Trim(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	src := args[0].String()
	cut := " \n\t\v\r"
	if len(args) > 1 {
		cut = args[1].String()
	}
	return runtime.String(strings.Trim(src, cut))
}
开发者ID:jmptrader,项目名称:agora,代码行数:15,代码来源:strings.go

示例10: os_Exec

func (o *OsMod) os_Exec(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	c := exec.Command(args[0].String(), toString(args[1:])...)
	b, e := c.CombinedOutput()
	if e != nil {
		panic(e)
	}
	return runtime.String(b)
}
开发者ID:jmptrader,项目名称:agora,代码行数:9,代码来源:os.go

示例11: strings_HasPrefix

// Returns true if the string at arg0 starts with any of the following strings.
// Args:
// 0 - The source string
// 1..n - The prefixes to test
// Returns:
// true if the source string starts with any of the specified prefixes
func (s *StringsMod) strings_HasPrefix(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	for _, v := range args[1:] {
		if strings.HasPrefix(src, v.String()) {
			return runtime.Bool(true)
		}
	}
	return runtime.Bool(false)
}
开发者ID:jmptrader,项目名称:agora,代码行数:16,代码来源:strings.go

示例12: strings_LastIndex

// Args:
// 0 - The source string
// 1 - [Optional] the start index in the source string
// 2 (or 1) .. n - The substrings to search for in the source string.
// Returns:
// The last index of the first found substring in source, if any is found, or -1
func (s *StringsMod) strings_LastIndex(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	start := 0
	find := 1
	switch v := args[1].(type) {
	case runtime.Number:
		runtime.ExpectAtLeastNArgs(3, args)
		start = int(v.Int())
		find = 2
	}
	src = src[start:]
	for _, v := range args[find:] {
		if ix := strings.LastIndex(src, v.String()); ix >= 0 {
			return runtime.Number(ix)
		}
	}
	return runtime.Number(-1)
}
开发者ID:jmptrader,项目名称:agora,代码行数:25,代码来源:strings.go

示例13: strings_Slice

// Slice a string to get a substring. Basically the same as slicing in Go.
// Args:
// 0 - The source string
// 1 - The start index
// 2 [optional] - The high bound, such that the length of the resulting string is high-start
// Results:
// The sliced string.
func (s *StringsMod) strings_Slice(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	start := args[1].Int()
	end := len(src)
	if len(args) > 2 {
		end = int(args[2].Int())
	}
	return runtime.String(src[start:end])
}
开发者ID:jmptrader,项目名称:agora,代码行数:17,代码来源:strings.go

示例14: strings_ToLower

// Converts strings to lowercase, concatenating all strings.
// Args:
// 0..n - The strings to convert to lower case and concatenate
// Returns:
// The lowercase string
func (s *StringsMod) strings_ToLower(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	buf := bytes.NewBuffer(nil)
	for _, v := range args {
		_, err := buf.WriteString(strings.ToLower(v.String()))
		if err != nil {
			panic(err)
		}
	}
	return runtime.String(buf.String())
}
开发者ID:jmptrader,项目名称:agora,代码行数:16,代码来源:strings.go

示例15: os_ReadDir

func (o *OsMod) os_ReadDir(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	fis, e := ioutil.ReadDir(args[0].String())
	if e != nil {
		panic(e)
	}
	ob := runtime.NewObject()
	for i, fi := range fis {
		ob.Set(runtime.Number(i), createFileInfo(fi))
	}
	return ob
}
开发者ID:jmptrader,项目名称:agora,代码行数:12,代码来源:os.go


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