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

Golang golua.State类代码示例

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

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



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

示例1: LuaNumParamsOk

func LuaNumParamsOk(L *lua.State, num_params int, name string) bool {
	n := L.GetTop()
	if n != num_params {
		err_str := fmt.Sprintf("%s expects exactly %d parameters, got %d.", name, num_params, n)
		LuaDoError(L, err_str)
		return false
	}
	return true
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:9,代码来源:script_utils.go


示例2: UpdatePlayer

func UpdatePlayer(p *Player, L *lua.State) {
	buffer := bytes.NewBuffer(nil)
	L.GetGlobal("store")
	err := LuaEncodeTable(buffer, L, -1)
	if err != nil {
		base.Warn().Printf("Error encoding lua state: %v", err)
	}
	L.Pop(1)
	p.Lua_store = buffer.Bytes()
}
开发者ID:RickDakan,项目名称:haunts,代码行数:10,代码来源:player.go


示例3: registerUtilityFunctions

// Ripped from game/ai/ai.go - should probably sync up with it
func registerUtilityFunctions(L *lua.State) {
	L.Register("print", func(L *lua.State) int {
		var res string
		n := L.GetTop()
		for i := -n; i < 0; i++ {
			res += LuaStringifyParam(L, i) + " "
		}
		base.Log().Printf("GameScript(%p): %s", L, res)
		return 0
	})
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:12,代码来源:script.go


示例4: LuaToEntity

// Gets the id out of the table at the specified index and returns the
// associated Entity, or nil if there is none.
func LuaToEntity(L *lua.State, game *Game, index int) *Entity {
	L.PushString("id")
	L.GetTable(index - 1)
	id := EntityId(L.ToInteger(-1))
	L.Pop(1)
	return game.EntityById(id)
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:9,代码来源:script_utils.go


示例5: readInput

func readInput(l *lua.State) {
	bstdin := bufio.NewReader(os.Stdin)
	for {
		var line string
		// TODO: Something better for windows?
		line, e := bstdin.ReadString('\n')
		if e != nil {
			shell.Println(e)
		}
		er := l.LoadString(line)
		if er != 0 {
			// Pop of the error description
			str := l.ToString(-1)
			shell.Println("Error loading: ", str)
			continue
		}
		er = l.PCall(0, lua.LUA_MULTRET, 0)
		if er != 0 {
			str := l.ToString(-1)
			shell.Println("Error running: ", str)
			continue
		}
		sesLog.Println(line)
	}
}
开发者ID:vron,项目名称:fm,代码行数:25,代码来源:lua.go


示例6: LuaToSpawnPoint

func LuaToSpawnPoint(L *lua.State, game *Game, pos int) *house.SpawnPoint {
	L.PushString("id")
	L.GetTable(pos - 1)
	index := L.ToInteger(-1)
	L.Pop(1)
	if index < 0 || index >= len(game.House.Floors[0].Spawns) {
		return nil
	}
	return game.House.Floors[0].Spawns[index]
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:10,代码来源:script_utils.go


示例7: LuaDecodeTable

// decodes a lua table and pushes it onto the stack
func LuaDecodeTable(r io.Reader, L *lua.State, g *Game) error {
	L.NewTable()
	var cont byte
	err := binary.Read(r, binary.LittleEndian, &cont)
	for cont != 0 && err == nil {
		for i := 0; i < 2 && err == nil; i++ {
			err = LuaDecodeValue(r, L, g)
		}
		if err == nil {
			err = binary.Read(r, binary.LittleEndian, &cont)
		}

		L.SetTable(-3)
	}
	if err != nil {
		return err
	}

	return nil
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:21,代码来源:script_utils.go


示例8: register

func register(l *lua.State) {
	for k, v := range funcs {
		// k is ideftifier string and v is the function to call

		// First we check the function
		t := reflect.TypeOf(v)
		if t.Kind() != reflect.Func {
			log.Println("Invalid function: ", k)
			continue
		}

		f, e := createwrap(reflect.ValueOf(v))

		if e != nil {
			log.Println("Error creating wrapper '", k, "': ", e)
			continue
		}

		l.Register(k, f)
	}
}
开发者ID:vron,项目名称:fm,代码行数:21,代码来源:lua.go


示例9: Push

func (exec aoeExec) Push(L *lua.State, g *game.Game) {
	exec.BasicActionExec.Push(L, g)
	if L.IsNil(-1) {
		return
	}
	L.PushString("Pos")
	game.LuaPushPoint(L, exec.X, exec.Y)
	L.SetTable(-3)
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:9,代码来源:aoe_attack.go


示例10: LuaDecodeValue

// Decodes a value from the reader and pushes it onto the stack
func LuaDecodeValue(r io.Reader, L *lua.State, g *Game) error {
	var le luaEncodable
	err := binary.Read(r, binary.LittleEndian, &le)
	if err != nil {
		return err
	}
	switch le {
	case luaEncBool:
		var v byte
		err = binary.Read(r, binary.LittleEndian, &v)
		L.PushBoolean(v == 1)
	case luaEncNumber:
		var f float64
		err = binary.Read(r, binary.LittleEndian, &f)
		L.PushNumber(f)
	case luaEncNil:
		L.PushNil()
	case luaEncEntity:
		var id uint64
		err = binary.Read(r, binary.LittleEndian, &id)
		ent := g.EntityById(EntityId(id))
		LuaPushEntity(L, ent)
		if ent != nil {
			base.Log().Printf("LUA: Push Ent %s", ent.Name)
		} else {
			base.Log().Printf("LUA: Push Ent NIL")
		}
	case luaEncTable:
		err = LuaDecodeTable(r, L, g)
	case luaEncString:
		var length uint32
		err = binary.Read(r, binary.LittleEndian, &length)
		if err != nil {
			return err
		}
		sb := make([]byte, length)
		err = binary.Read(r, binary.LittleEndian, &sb)
		L.PushString(string(sb))
	default:
		return errors.New(fmt.Sprintf("Unknown lua value id == %d.", le))
	}
	if err != nil {
		return err
	}
	return nil
}
开发者ID:RickDakan,项目名称:haunts,代码行数:47,代码来源:script_utils.go


示例11: Push

func (exec summonExec) Push(L *lua.State, g *game.Game) {
	exec.BasicActionExec.Push(L, g)
	if L.IsNil(-1) {
		return
	}
	_, x, y := g.FromVertex(exec.Pos)
	L.PushString("Pos")
	game.LuaPushPoint(L, x, y)
	L.SetTable(-3)
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:10,代码来源:summon.go


示例12: main

func main() {
	var L *lua.State
	L = lua.NewState()
	L.OpenLibs()

	rawptr := L.NewUserdata(uintptr(unsafe.Sizeof(Userdata{})))
	var ptr *Userdata
	ptr = (*Userdata)(rawptr)
	ptr.a = 2
	ptr.b = 3

	fmt.Println(ptr)

	rawptr2 := L.ToUserdata(-1)
	ptr2 := (*Userdata)(rawptr2)

	fmt.Println(ptr2)
}
开发者ID:runningwild,项目名称:golua,代码行数:18,代码来源:userdata.go


示例13: LuaEncodeTable

func LuaEncodeTable(w io.Writer, L *lua.State, index int) error {
	L.PushNil()
	for L.Next(index-1) != 0 {
		binary.Write(w, binary.LittleEndian, byte(1))
		err := LuaEncodeValue(w, L, -2)
		if err != nil {
			return err
		}
		err = LuaEncodeValue(w, L, -1)
		if err != nil {
			return err
		}
		L.Pop(1)
	}
	return binary.Write(w, binary.LittleEndian, byte(0))
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:16,代码来源:script_utils.go


示例14: LuaStringifyParam

func LuaStringifyParam(L *lua.State, index int) string {
	if L.IsTable(index) {
		str := "table <not implemented> {"
		return str
		first := true
		L.PushNil()
		for L.Next(index-1) != 0 {
			if !first {
				str += ", "
			}
			first = false
			str += fmt.Sprintf("(%s) -> (%s)", LuaStringifyParam(L, -2), LuaStringifyParam(L, -1))
			L.Pop(1)
		}
		return str + "}"
	}
	if L.IsBoolean(index) {
		if L.ToBoolean(index) {
			return "true"
		}
		return "false"
	}
	return L.ToString(index)
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:24,代码来源:script_utils.go


示例15: LuaDoError

func LuaDoError(L *lua.State, err_str string) {
	base.Error().Printf(err_str)
	L.PushString(err_str)
	L.SetExecutionLimit(1)
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:5,代码来源:script_utils.go


示例16: LuaCheckParamsOk

func LuaCheckParamsOk(L *lua.State, name string, params ...LuaType) bool {
	fmt.Sprintf("%s(")
	n := L.GetTop()
	if n != len(params) {
		LuaDoError(L, fmt.Sprintf("Got %d parameters to %s.", n, luaMakeSigniature(name, params)))
		return false
	}
	for i := -n; i < 0; i++ {
		ok := false
		switch params[i+n] {
		case LuaInteger:
			ok = L.IsNumber(i)
		case LuaFloat:
			ok = L.IsNumber(i)
		case LuaBoolean:
			ok = L.IsBoolean(i)
		case LuaString:
			ok = L.IsString(i)
		case LuaEntity:
			if L.IsTable(i) {
				L.PushNil()
				for L.Next(i-1) != 0 {
					if L.ToString(-2) == "type" && L.ToString(-1) == "Entity" {
						ok = true
					}
					L.Pop(1)
				}
			}
		case LuaPoint:
			if L.IsTable(i) {
				var x, y bool
				L.PushNil()
				for L.Next(i-1) != 0 {
					if L.ToString(-2) == "X" {
						x = true
					}
					if L.ToString(-2) == "Y" {
						y = true
					}
					L.Pop(1)
				}
				ok = x && y
			}
		case LuaRoom:
			if L.IsTable(i) {
				var floor, room, door bool
				L.PushNil()
				for L.Next(i-1) != 0 {
					switch L.ToString(-2) {
					case "floor":
						floor = true
					case "room":
						room = true
					case "door":
						door = true
					}
					L.Pop(1)
				}
				ok = floor && room && !door
			}
		case LuaDoor:
			if L.IsTable(i) {
				var floor, room, door bool
				L.PushNil()
				for L.Next(i-1) != 0 {
					switch L.ToString(-2) {
					case "floor":
						floor = true
					case "room":
						room = true
					case "door":
						door = true
					}
					L.Pop(1)
				}
				ok = floor && room && door
			}
		case LuaSpawnPoint:
			if L.IsTable(i) {
				L.PushNil()
				for L.Next(i-1) != 0 {
					if L.ToString(-2) == "type" && L.ToString(-1) == "SpawnPoint" {
						ok = true
					}
					L.Pop(1)
				}
			}
		case LuaArray:
			// Make sure that all of the indices 1..length are there, and no others.
			check := make(map[int]int)
			if L.IsTable(i) {
				L.PushNil()
				for L.Next(i-1) != 0 {
					if L.IsNumber(-2) {
						check[L.ToInteger(-2)]++
					} else {
						break
					}
					L.Pop(1)
				}
//.........这里部分代码省略.........
开发者ID:FlyingCar,项目名称:haunts,代码行数:101,代码来源:script_utils.go


示例17: LuaEncodeValue

// Encodes a lua value, only bool, number, nil, table, and string can be
// encoded.  If an unencodable value is encountered an error will be
// returned.
func LuaEncodeValue(w io.Writer, L *lua.State, index int) error {
	var err1, err2, err3 error
	switch {
	case L.IsBoolean(index):
		err1 = binary.Write(w, binary.LittleEndian, luaEncBool)
		var v byte = 0
		if L.ToBoolean(index) {
			v = 1
		}
		err2 = binary.Write(w, binary.LittleEndian, v)
	case L.IsNumber(index):
		err1 = binary.Write(w, binary.LittleEndian, luaEncNumber)
		err2 = binary.Write(w, binary.LittleEndian, L.ToNumber(index))
	case L.IsNil(index):
		err1 = binary.Write(w, binary.LittleEndian, luaEncNil)
	case LuaIsEntity(L, index):
		err1 = binary.Write(w, binary.LittleEndian, luaEncEntity)
		L.PushString("id")
		L.GetTable(index - 1)
		err2 = binary.Write(w, binary.LittleEndian, uint64(L.ToInteger(-1)))
		L.Pop(1)
	case L.IsTable(index):
		err1 = binary.Write(w, binary.LittleEndian, luaEncTable)
		err2 = LuaEncodeTable(w, L, index)
	case L.IsString(index):
		err1 = binary.Write(w, binary.LittleEndian, luaEncString)
		str := L.ToString(index)
		err2 = binary.Write(w, binary.LittleEndian, uint32(len(str)))
		err3 = binary.Write(w, binary.LittleEndian, []byte(str))
	default:
		return errors.New(fmt.Sprintf("Cannot encode lua type id == %d.", L.Type(index)))
	}
	switch {
	case err1 != nil:
		return err1
	case err2 != nil:
		return err2
	case err3 != nil:
		return err3
	}
	return nil
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:45,代码来源:script_utils.go


示例18: LuaPushSpawnPoint

func LuaPushSpawnPoint(L *lua.State, game *Game, sp *house.SpawnPoint) {
	index := -1
	for i, spawn := range game.House.Floors[0].Spawns {
		if spawn == sp {
			index = i
		}
	}
	if index == -1 {
		LuaDoError(L, "Unable to push SpawnPoint, not found in the house.")
		L.NewTable()
		L.PushString("id")
		L.PushInteger(-1)
		L.SetTable(-3)
		L.PushString("type")
		L.PushString("SpawnPoint")
		L.SetTable(-3)
		return
	}
	L.NewTable()
	x, y := sp.Pos()
	dx, dy := sp.Dims()
	L.PushString("id")
	L.PushInteger(index)
	L.SetTable(-3)
	L.PushString("type")
	L.PushString("SpawnPoint")
	L.SetTable(-3)
	L.PushString("Name")
	L.PushString(sp.Name)
	L.SetTable(-3)
	L.PushString("Pos")
	LuaPushPoint(L, x, y)
	L.SetTable(-3)
	L.PushString("Dims")
	LuaPushDims(L, dx, dy)
	L.SetTable(-3)
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:37,代码来源:script_utils.go


示例19: LuaToDoor

func LuaToDoor(L *lua.State, game *Game, index int) *house.Door {
	L.PushString("floor")
	L.GetTable(index - 1)
	floor := L.ToInteger(-1)
	L.Pop(1)
	L.PushString("room")
	L.GetTable(index - 1)
	room := L.ToInteger(-1)
	L.Pop(1)
	L.PushString("door")
	L.GetTable(index - 1)
	door := L.ToInteger(-1)
	L.Pop(1)

	if floor < 0 || floor >= len(game.House.Floors) {
		return nil
	}
	if room < 0 || room >= len(game.House.Floors[floor].Rooms) {
		return nil
	}
	if door < 0 || door >= len(game.House.Floors[floor].Rooms[room].Doors) {
		return nil
	}

	return game.House.Floors[floor].Rooms[room].Doors[door]
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:26,代码来源:script_utils.go


示例20: LuaPushDoor

func LuaPushDoor(L *lua.State, game *Game, door *house.Door) {
	for fi, f := range game.House.Floors {
		for ri, r := range f.Rooms {
			for di, d := range r.Doors {
				if d == door {
					L.NewTable()
					L.PushString("type")
					L.PushString("door")
					L.SetTable(-3)
					L.PushString("floor")
					L.PushInteger(fi)
					L.SetTable(-3)
					L.PushString("room")
					L.PushInteger(ri)
					L.SetTable(-3)
					L.PushString("door")
					L.PushInteger(di)
					L.SetTable(-3)
					return
				}
			}
		}
	}
	L.PushNil()
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:25,代码来源:script_utils.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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