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

Golang runtime.Number函数代码示例

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

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



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

示例1: 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


示例2: Param

func (jm *JotaModule) Param(vs ...runtime.Val) runtime.Val {
	jm.dieOnTerminated()
	jm.paramsMutex.Lock()
	defer jm.paramsMutex.Unlock()
	paramName := vs[0].String()
	value, ok := jm.params[paramName]
	if !ok {
		return runtime.Nil
	}
	switch t := value.(type) {
	case string:
		return runtime.String(t)
	case bool:
		return runtime.Bool(t)
	case int:
		return runtime.Number(t)
	case float64:
		return runtime.Number(t)
	case linear.Vec2:
		return jm.newVec(t.X, t.Y)
	case game.Gid:
		return jm.newEnt(t)
	default:
		base.Error().Printf("Requested parameter of unexpected type: %T", t)
		return runtime.Nil
	}
}
开发者ID:runningwild,项目名称:jota,代码行数:27,代码来源:scripts.go


示例3: TestStringsSplit

func TestStringsSplit(t *testing.T) {
	ctx := runtime.NewCtx(nil, nil)
	sm := new(StringsMod)
	sm.SetCtx(ctx)
	ret := sm.strings_Split(runtime.String("aa:bb::dd"), runtime.String(":"))
	ob := ret.(runtime.Object)
	exp := []string{"aa", "bb", "", "dd"}
	if l := ob.Len().Int(); l != int64(len(exp)) {
		t.Errorf("expected split length of %d, got %d", len(exp), l)
	}
	for i, v := range exp {
		got := ob.Get(runtime.Number(i))
		if got.String() != v {
			t.Errorf("expected split index %d to be %s, got %s", i, v, got)
		}
	}
	ret = sm.strings_Split(runtime.String("aa:bb::dd:ee:"), runtime.String(":"), runtime.Number(2))
	ob = ret.(runtime.Object)
	exp = []string{"aa", "bb::dd:ee:"}
	if l := ob.Len().Int(); l != int64(len(exp)) {
		t.Errorf("expected split length of %d, got %d", len(exp), l)
	}
	for i, v := range exp {
		got := ob.Get(runtime.Number(i))
		if got.String() != v {
			t.Errorf("expected split index %d to be %s, got %s", i, v, got)
		}
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:29,代码来源:strings_test.go


示例4: TestMin

func TestMin(t *testing.T) {
	ctx := runtime.NewCtx(nil, nil)
	mm := new(MathMod)
	mm.SetCtx(ctx)

	cases := []struct {
		src []runtime.Val
		exp runtime.Val
	}{
		0: {
			src: []runtime.Val{runtime.Number(3), runtime.Number(0), runtime.Number(-12.74), runtime.Number(1)},
			exp: runtime.Number(-12.74),
		},
		1: {
			src: []runtime.Val{runtime.String("24"), runtime.Bool(true), runtime.Number(12.74)},
			exp: runtime.Number(1),
		},
		2: {
			src: []runtime.Val{runtime.Number(0), runtime.String("0")},
			exp: runtime.Number(0),
		},
	}

	for i, c := range cases {
		ret := mm.math_Min(c.src...)
		if ret != c.exp {
			t.Errorf("[%d] - expected %f, got %f", i, c.exp.Float(), ret.Float())
		}
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:30,代码来源:math_test.go


示例5: TestMathIsInf

func TestMathIsInf(t *testing.T) {
	// This is just an interface to Go's function, so just a quick simple test
	ctx := runtime.NewCtx(nil, nil)
	mm := new(MathMod)
	mm.SetCtx(ctx)
	val := 3.12
	val2 := 1
	ret := mm.math_IsInf(runtime.Number(val), runtime.Number(val2))
	exp := math.IsInf(val, val2)
	if ret.Bool() != exp {
		t.Errorf("expected %v, got %v", exp, ret.Bool())
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:13,代码来源:math_test.go


示例6: newVec

func (jm *JotaModule) newVec(x, y float64) *agoraVec {
	ob := runtime.NewObject()
	v := &agoraVec{
		Object: ob,
		jm:     jm,
	}
	ob.Set(runtime.String("Length"), runtime.NewNativeFunc(jm.ctx, "jota.Vec.Length", v.length))
	ob.Set(runtime.String("Sub"), runtime.NewNativeFunc(jm.ctx, "jota.Vec.Sub", v.sub))
	ob.Set(runtime.String("Angle"), runtime.NewNativeFunc(jm.ctx, "jota.Vec.Angle", v.angle))
	ob.Set(runtime.String("X"), runtime.Number(x))
	ob.Set(runtime.String("Y"), runtime.Number(y))
	return v
}
开发者ID:runningwild,项目名称:jota,代码行数:13,代码来源:scripts.go


示例7: math_Rand

func (m *MathMod) math_Rand(args ...runtime.Val) runtime.Val {
	switch len(args) {
	case 0:
		return runtime.Number(rand.Int())
	case 1:
		return runtime.Number(rand.Intn(int(args[0].Int())))
	default:
		low := args[0].Int()
		high := args[1].Int()
		n := rand.Intn(int(high - low))
		return runtime.Number(int64(n) + low)
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:13,代码来源:math.go


示例8: TestMathPow

func TestMathPow(t *testing.T) {
	// This is just an interface to Go's function, so just a quick simple test
	ctx := runtime.NewCtx(nil, nil)
	mm := new(MathMod)
	mm.SetCtx(ctx)
	val := 1.12
	val2 := 3.45
	ret := mm.math_Pow(runtime.Number(val), runtime.Number(val2))
	exp := math.Pow(val, val2)
	if ret.Float() != exp {
		t.Errorf("expected %f, got %f", exp, ret.Float())
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:13,代码来源:math_test.go


示例9: TestStringsSlice

func TestStringsSlice(t *testing.T) {
	ctx := runtime.NewCtx(nil, nil)
	sm := new(StringsMod)
	sm.SetCtx(ctx)
	ret := sm.strings_Slice(runtime.String("agora"), runtime.Number(2))
	exp := "ora"
	if ret.String() != exp {
		t.Errorf("expected %s, got %s", exp, ret)
	}
	ret = sm.strings_Slice(runtime.String("agora"), runtime.Number(2), runtime.Number(4))
	exp = "or"
	if ret.String() != exp {
		t.Errorf("expected %s, got %s", exp, ret)
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:15,代码来源:strings_test.go


示例10: TestStringsReplace

func TestStringsReplace(t *testing.T) {
	cases := []struct {
		args []runtime.Val
		exp  string
	}{
		0: {
			args: []runtime.Val{
				runtime.String("this is the source"),
				runtime.String("th"),
			},
			exp: "is is e source",
		},
		1: {
			args: []runtime.Val{
				runtime.String("this is the source"),
				runtime.String("th"),
				runtime.Number(1),
			},
			exp: "is is the source",
		},
		2: {
			args: []runtime.Val{
				runtime.String("this is the source"),
				runtime.String("t"),
				runtime.String("T"),
			},
			exp: "This is The source",
		},
		3: {
			args: []runtime.Val{
				runtime.String("this is the source"),
				runtime.String("t"),
				runtime.String("T"),
				runtime.Number(1),
			},
			exp: "This is the source",
		},
	}
	ctx := runtime.NewCtx(nil, nil)
	sm := new(StringsMod)
	sm.SetCtx(ctx)
	for i, c := range cases {
		ret := sm.strings_Replace(c.args...)
		if ret.String() != c.exp {
			t.Errorf("[%d] - expected %s, got %s", i, c.exp, ret)
		}
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:48,代码来源:strings_test.go


示例11: NearbyEnts

func (jm *JotaModule) NearbyEnts(vs ...runtime.Val) runtime.Val {
	jm.dieOnTerminated()
	jm.engine.Pause()
	defer jm.engine.Unpause()
	g := jm.engine.GetState().(*game.Game)
	me := g.Ents[jm.myGid]
	obj := runtime.NewObject()
	if me == nil {
		return obj
	}

	ents := g.EntsInRange(me.Pos(), me.Stats().Vision())
	var eds entDistSlice
	for _, ent := range ents {
		if ent == me {
			continue
		}
		dist := ent.Pos().Sub(me.Pos()).Mag()
		if dist > me.Stats().Vision() {
			continue
		}
		if ent.Stats().Cloaking() > 0.9 && ent.Side() != me.Side() {
			continue
		}
		if g.ExistsLos(me.Pos(), ent.Pos()) {
			eds.ents = append(eds.ents, ent)
			eds.dist = append(eds.dist, dist)
		}
	}
	sort.Sort(&eds)
	for i, ent := range eds.ents {
		obj.Set(runtime.Number(i), jm.newEnt(ent.Id()))
	}
	return obj
}
开发者ID:runningwild,项目名称:jota,代码行数:35,代码来源:scripts.go


示例12: createFileInfo

func createFileInfo(fi os.FileInfo) runtime.Val {
	o := runtime.NewObject()
	o.Set(runtime.String("Name"), runtime.String(fi.Name()))
	o.Set(runtime.String("Size"), runtime.Number(fi.Size()))
	o.Set(runtime.String("IsDir"), runtime.Bool(fi.IsDir()))
	return o
}
开发者ID:jmptrader,项目名称:agora,代码行数:7,代码来源:os.go


示例13: fmt_Scanint

func (f *FmtMod) fmt_Scanint(args ...runtime.Val) runtime.Val {
	var i int
	if _, e := fmt.Fscanf(f.ctx.Stdin, "%d", &i); e != nil {
		panic(e)
	}
	return runtime.Number(i)
}
开发者ID:jmptrader,项目名称:agora,代码行数:7,代码来源:fmt.go


示例14: 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


示例15: writeLine

func (of *file) writeLine(args ...runtime.Val) runtime.Val {
	n := of.write(args...)
	m, e := of.f.WriteString("\n")
	if e != nil {
		panic(e)
	}
	return runtime.Number(int(n.Int()) + m)
}
开发者ID:jmptrader,项目名称:agora,代码行数:8,代码来源:os.go


示例16: 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


示例17: fmt_Println

func (f *FmtMod) fmt_Println(args ...runtime.Val) runtime.Val {
	ifs := toStringIface(args)
	n, err := fmt.Fprintln(f.ctx.Stdout, ifs...)
	if err != nil {
		panic(err)
	}
	return runtime.Number(n)
}
开发者ID:jmptrader,项目名称:agora,代码行数:8,代码来源:fmt.go


示例18: TestTimeConv

func TestTimeConv(t *testing.T) {
	ctx := runtime.NewCtx(nil, nil)
	tm := new(TimeMod)
	tm.SetCtx(ctx)
	nw := time.Now().UTC()
	n := tm.time_Date(runtime.Number(nw.Year()),
		runtime.Number(nw.Month()),
		runtime.Number(nw.Day()),
		runtime.Number(nw.Hour()),
		runtime.Number(nw.Minute()),
		runtime.Number(nw.Second()),
		runtime.Number(nw.Nanosecond()))
	ob := n.(runtime.Object)
	cnv := ob.Get(runtime.String("__string"))
	f := cnv.(runtime.Func)
	ret := f.Call(nil)
	exp := nw.Format(time.RFC3339)
	if ret.String() != exp {
		t.Errorf("expected string to return '%s', got '%s'", exp, ret)
	}
	cnv = ob.Get(runtime.String("__int"))
	f = cnv.(runtime.Func)
	ret = f.Call(nil)
	{
		exp := nw.Unix()
		if ret.Int() != int64(exp) {
			t.Errorf("expected int to return %d, got %d", exp, ret.Int())
		}
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:30,代码来源:time_test.go


示例19: angle

func (aEnt *agoraEnt) angle(args ...runtime.Val) runtime.Val {
	aEnt.jm.engine.Pause()
	defer aEnt.jm.engine.Unpause()
	ent := aEnt.jm.engine.GetState().(*game.Game).Ents[aEnt.gid]
	if ent == nil {
		return runtime.Nil
	}
	return runtime.Number(ent.Angle())
}
开发者ID:runningwild,项目名称:jota,代码行数:9,代码来源:scripts.go


示例20: TestTimeSleep

func TestTimeSleep(t *testing.T) {
	ctx := runtime.NewCtx(nil, nil)
	tm := new(TimeMod)
	tm.SetCtx(ctx)
	n := time.Now()
	tm.time_Sleep(runtime.Number(100))
	if diff := time.Now().Sub(n); diff < 100*time.Millisecond {
		t.Errorf("expected at least 100ms, got %f", diff.Seconds()*1000)
	}
}
开发者ID:jmptrader,项目名称:agora,代码行数:10,代码来源:time_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang runtime.String函数代码示例发布时间:2022-05-28
下一篇:
Golang runtime.NewCtx函数代码示例发布时间: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