• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang runtime.ExpectAtLeastNArgs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: strings_Split

// Args:
// 0 - the source string
// 1 - the separator
// 2 [optional] - the maximum number of splits, defaults to all
// Returns:
// An array-like object with splits as values and indices as keys.
func (s *StringsMod) strings_Split(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	sep := args[1].String()
	cnt := -1
	if len(args) > 2 {
		cnt = int(args[2].Int())
	}
	splits := strings.SplitN(src, sep, cnt)
	ob := runtime.NewObject()
	for i, v := range splits {
		ob.Set(runtime.Number(i), runtime.String(v))
	}
	return ob
}
开发者ID:jmptrader,项目名称:agora,代码行数:21,代码来源:strings.go


示例17: os_WriteFile

func (o *OsMod) os_WriteFile(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	f, e := os.Create(args[0].String())
	if e != nil {
		panic(e)
	}
	defer f.Close()
	n := 0
	for _, v := range args[1:] {
		m, e := f.WriteString(v.String())
		if e != nil {
			panic(e)
		}
		n += m
	}
	return runtime.Number(n)
}
开发者ID:jmptrader,项目名称:agora,代码行数:17,代码来源:os.go


示例18: strings_Replace

// Args:
// 0 - The source string
// 1 - The old substring to replace
// 2 [optional] - the new substring to insert (none by default, delete only)
// 3 [optional] - the number of occurrences to replace. If 2 is a number, it is
// considered the value of 3 and 2 is empty.
// Returns:
// The string with n occurrences of old replaced by new.
func (s *StringsMod) strings_Replace(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(2, args)
	src := args[0].String()
	old := args[1].String()
	nw := ""
	cnt := -1
	if len(args) > 2 {
		switch v := args[2].(type) {
		case runtime.Number:
			cnt = int(v.Int())
		default:
			// args[2] is the new string, args[3], if present, is the count
			nw = v.String()
			if len(args) > 3 {
				cnt = int(args[3].Int())
			}
		}
	}
	return runtime.String(strings.Replace(src, old, nw, cnt))
}
开发者ID:jmptrader,项目名称:agora,代码行数:28,代码来源:strings.go


示例19: strings_Join

// Args:
// 0 - The source object
// 1 - The separator, empty string by default
// Returns:
// The concatenated string of all the array-like indices of the source object.
func (s *StringsMod) strings_Join(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	ob := args[0].(runtime.Object)
	sep := ""
	if len(args) > 1 {
		sep = args[1].String()
	}
	l := int(ob.Len().Int())
	buf := bytes.NewBuffer(nil)
	for i := 0; i < l; i++ {
		val := ob.Get(runtime.Number(i))
		if _, err := buf.WriteString(val.String()); err != nil {
			panic(err)
		}
		if i < l-1 {
			if _, err := buf.WriteString(sep); err != nil {
				panic(err)
			}
		}
	}
	return runtime.String(buf.String())
}
开发者ID:jmptrader,项目名称:agora,代码行数:27,代码来源:strings.go


示例20: os_Open

func (o *OsMod) os_Open(args ...runtime.Val) runtime.Val {
	runtime.ExpectAtLeastNArgs(1, args)
	nm := args[0].String()
	flg := "r" // defaults to read-only
	if len(args) > 1 {
		// Second arg is the flag (same as C's fopen)
		// r  - open for reading
		// w  - open for writing (file need not exist)
		// a  - open for appending (file need not exist)
		// r+ - open for reading and writing, start at beginning
		// w+ - open for reading and writing (overwrite file)
		// a+ - open for reading and writing (append if file exists)
		flg = args[1].String()
	}
	var flgi int
	switch flg {
	case "r":
		flgi = os.O_RDONLY
	case "w":
		flgi = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
	case "a":
		flgi = os.O_APPEND | os.O_CREATE
	case "r+":
		flgi = os.O_RDWR
	case "w+":
		flgi = os.O_RDWR | os.O_CREATE | os.O_TRUNC
	case "a+":
		flgi = os.O_RDWR | os.O_APPEND | os.O_CREATE
	default:
		panic("invalid file flag mode: " + flg)
	}
	f, e := os.OpenFile(nm, flgi, 0666)
	if e != nil {
		panic(e)
	}
	return o.newFile(f)
}
开发者ID:jmptrader,项目名称:agora,代码行数:37,代码来源:os.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang runtime.NewCtx函数代码示例发布时间:2022-05-28
下一篇:
Golang pubnubMessaging.Pubnub类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap