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


Golang golua.State类代码示例

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


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


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