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


Golang State.PushInteger方法代码示例

本文整理汇总了Golang中github.com/aarzilli/golua/lua.State.PushInteger方法的典型用法代码示例。如果您正苦于以下问题:Golang State.PushInteger方法的具体用法?Golang State.PushInteger怎么用?Golang State.PushInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aarzilli/golua/lua.State的用法示例。


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

示例1: pushMap

func pushMap(L *lua.State, m map[string]interface{}, lower bool) {
	L.CreateTable(0, len(m))
	for k, v := range m {
		if lower {
			L.PushString(strings.ToLower(k))
		} else {
			L.PushString(k)
		}
		switch t := v.(type) {
		case string:
			L.PushString(t)
		case int64:
			L.PushInteger(t)
		case int:
			L.PushInteger(int64(t))
		case float64:
			L.PushNumber(t)
		case bool:
			L.PushBoolean(t)
		case map[string]interface{}:
			pushMap(L, t, false)
		default:
			L.PushNil()
		}
		L.SetTable(-3)
	}
}
开发者ID:12foo,项目名称:apiplexy,代码行数:27,代码来源:lua.go

示例2: copySliceToTable

// Also for arrays.
func copySliceToTable(L *lua.State, vslice reflect.Value, visited visitor) int {
	ref := vslice
	for vslice.Kind() == reflect.Ptr {
		// For arrays.
		vslice = vslice.Elem()
	}

	if vslice.IsValid() && (vslice.Kind() == reflect.Slice || vslice.Kind() == reflect.Array) {
		n := vslice.Len()
		L.CreateTable(n, 0)
		if vslice.Kind() == reflect.Slice {
			visited.mark(vslice)
		} else if ref.Kind() == reflect.Ptr {
			visited.mark(ref)
		}

		for i := 0; i < n; i++ {
			L.PushInteger(int64(i + 1))
			v := vslice.Index(i)
			if isNil(v) {
				v = nullv
			}
			goToLua(L, nil, v, true, visited)
			L.SetTable(-3)
		}
		return 1
	}
	L.PushNil()
	L.PushString("not a slice/array")
	return 2
}
开发者ID:stevedonovan,项目名称:luar,代码行数:32,代码来源:luar.go

示例3: apiAudioBitrate

func (p *Plugin) apiAudioBitrate(l *lua.State) int {
	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		l.PushInteger(int64(enc.Bitrate()))
	} else {
		l.PushInteger(-1)
	}
	return 1
}
开发者ID:mgalvey,项目名称:piepan,代码行数:8,代码来源:audio.go

示例4: ipairsAux

func ipairsAux(L *lua.State) int {
	i := L.CheckInteger(2) + 1
	L.PushInteger(int64(i))
	L.PushInteger(int64(i))
	L.GetTable(1)
	if L.Type(-1) == lua.LUA_TNIL {
		return 1
	}
	return 2
}
开发者ID:stevedonovan,项目名称:luar,代码行数:10,代码来源:proxyfuncs.go

示例5: MessThingContents

func MessThingContents(state *lua.State, thing *Thing) int {
	// make a new table
	state.CreateTable(len(thing.Contents), 0) // ( -- tbl )
	// for each content add a new lua-space Thing
	for i, contentId := range thing.Contents {
		state.PushInteger(int64(i))
		pushValue(state, contentId)
		state.SetTable(-3) // ( tbl key val -- tbl )
	} // ( tbl -- tbl )
	return 1
}
开发者ID:natmeox,项目名称:mess,代码行数:11,代码来源:softcode.go

示例6: ProxyIpairs

// ProxyIpairs implements Lua 5.2 'ipairs' functions.
// It respects the __ipairs metamethod.
//
// It is only useful for compatibility with Lua 5.1.
func ProxyIpairs(L *lua.State) int {
	// See Lua >=5.2 source code.
	if L.GetMetaField(1, "__ipairs") {
		L.PushValue(1)
		L.Call(1, 3)
		return 3
	}

	L.CheckType(1, lua.LUA_TTABLE)
	L.PushGoFunction(ipairsAux)
	L.PushValue(1)
	L.PushInteger(0)
	return 3
}
开发者ID:stevedonovan,项目名称:luar,代码行数:18,代码来源:proxyfuncs.go

示例7: LuaIntTimestamp

func LuaIntTimestamp(L *lua.State) int {
	luaAssertArgnum(L, 1, "timestamp()")

	if !L.IsTable(-1) {
		panic(errors.New("Argoment of timestamp is not a table"))
		return 0
	}

	L.CheckStack(1)

	t := time.Date(GetTableInt(L, "year"), time.Month(GetTableInt(L, "month")), GetTableInt(L, "day"), GetTableInt(L, "hour"), GetTableInt(L, "minute"), GetTableInt(L, "second"), 0, time.Local)

	L.PushInteger(int64(t.Unix()))
	return 1
}
开发者ID:aarzilli,项目名称:pooch,代码行数:15,代码来源:luaint.go

示例8: CopySliceToTable

// copy a Go slice to a Lua table
func CopySliceToTable(L *lua.State, vslice reflect.Value) int {
	if vslice.IsValid() && vslice.Type().Kind() == reflect.Slice {
		n := vslice.Len()
		L.CreateTable(n, 0)
		for i := 0; i < n; i++ {
			L.PushInteger(int64(i + 1))
			GoToLua(L, nil, vslice.Index(i))
			L.SetTable(-3)
		}
		return 1
	} else {
		L.PushNil()
		L.PushString("not a slice!")
	}
	return 2
}
开发者ID:kdar,项目名称:luar,代码行数:17,代码来源:luar.go

示例9: LuaIntParseDateTime

func LuaIntParseDateTime(L *lua.State) int {
	luaAssertArgnum(L, 1, "parsedatetime()")

	L.CheckStack(1)

	input := L.ToString(-1)
	tl := GetTasklistFromLua(L)

	out, _ := ParseDateTime(input, tl.GetTimezone())

	if out != nil {
		L.PushInteger(int64(out.Unix()))
	} else {
		L.PushInteger(0)
	}

	return 1
}
开发者ID:aarzilli,项目名称:pooch,代码行数:18,代码来源:luaint.go

示例10: LuaIntGetterSetterFunctionInt

func LuaIntGetterSetterFunctionInt(fname string, L *lua.State, getter func(tl *Tasklist, entry *Entry) int64, setter func(tl *Tasklist, entry *Entry, value int)) int {
	argNum := L.GetTop()

	if argNum == 0 {
		entry := GetEntryFromLua(L, CURSOR, fname)
		tl := GetTasklistFromLua(L)
		L.PushInteger(getter(tl, entry))
		return 1
	} else if argNum == 1 {
		value := L.ToInteger(1)
		entry := GetEntryFromLua(L, CURSOR, fname)
		tl := GetTasklistFromLua(L)
		setter(tl, entry, value)
		if !tl.luaFlags.cursorCloned {
			tl.luaFlags.cursorEdited = true
		}
		return 0
	}

	panic(errors.New(fmt.Sprintf("Incorrect number of argoments to %s (only 0 or 1 accepted)", fname)))
	return 0
}
开发者ID:aarzilli,项目名称:pooch,代码行数:22,代码来源:luaint.go

示例11: slicemap__len

func slicemap__len(L *lua.State) int {
	val, _ := valueOfProxy(L, 1)
	L.PushInteger(int64(val.Len()))
	return 1
}
开发者ID:imvu,项目名称:Tetra,代码行数:5,代码来源:luar.go

示例12: pushValue

func pushValue(state *lua.State, value interface{}) error {
	switch v := value.(type) {
	default:
		return fmt.Errorf("An item of unknown type was included in the environment or arguments of a Lua call (skipping it): %v",
			value)
	case nil:
		log.Println("Pushing nil onto lua stack")
		state.PushNil()
	case string:
		log.Println("Pushing string onto lua stack")
		state.PushString(v)
	case int:
		log.Println("Pushing int onto lua stack")
		state.PushInteger(int64(v))
	case int64:
		log.Println("Pushing int64 onto lua stack")
		state.PushInteger(v)
	case float64:
		log.Println("Pushing float64 onto lua stack")
		state.PushNumber(v)
	case bool:
		log.Println("Pushing bool onto lua stack")
		state.PushBoolean(v)

	case map[string]interface{}:
		log.Println("Pushing map[string]interface{} onto lua stack")
		state.CreateTable(0, len(v))
		for name, value := range v {
			err := pushValue(state, value)
			if err != nil {
				// error means nothing was added to stack. So pop our new table so *we* leave nothing added to the stack.
				state.Pop(1)
				return err
			}
			state.SetField(-2, name)
		}
		// then leave the table on the stack

	case ThingType:
		// These are singleton sentinel values, so load them from Lua-land.
		state.GetGlobal("world")
		state.GetField(-1, strings.Title(v.String()))
		state.Remove(-2)

	case *Thing:
		log.Println("Pushing *Thing onto lua stack")
		return pushValue(state, v.Id)
	case ThingId:
		log.Println("Pushing ThingId onto lua stack")
		// We're pushing a ThingId, so make a new userdata for it, with the Thing metatable.
		userdata := state.NewUserdata(uintptr(unsafe.Sizeof(int64(0))))
		thingPtr := (*int64)(userdata)
		*thingPtr = int64(v)
		if !state.IsUserdata(-1) {
			log.Println("!!! HOGAD JUST PUSHED NEW USERDATA BUT IT ISN'T OMG !!!")
		}
		log.Println("Pushed ThingId", *thingPtr, "onto lua stack")

		// Now make it act like a Thing.
		state.LGetMetaTable(ThingMetaTableName) // ( udata -- udata mtbl )
		state.SetMetaTable(-2)                  // ( udata mtbl -- udata )

		// Let's just check that it's that, for sures.
		if !state.IsUserdata(-1) {
			log.Println("!!! WOOP WOOP DID NOT SET METATABLE RIGHT :( !!!")
		}
	}
	return nil
}
开发者ID:natmeox,项目名称:mess,代码行数:69,代码来源:softcode.go

示例13: SetTableIntString

func SetTableIntString(L *lua.State, idx int64, value string) {
	L.PushInteger(idx)
	L.PushString(value)
	L.SetTable(-3)
}
开发者ID:aarzilli,项目名称:pooch,代码行数:5,代码来源:luaint.go

示例14: SetTableInt

func SetTableInt(L *lua.State, name string, value int64) {
	// Remember to check stack for 2 extra locations
	L.PushString(name)
	L.PushInteger(value)
	L.SetTable(-3)
}
开发者ID:aarzilli,项目名称:pooch,代码行数:6,代码来源:luaint.go


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