本文整理汇总了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
}
示例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()
}
示例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
})
}
示例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)
}
示例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)
}
}
示例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]
}
示例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
}
示例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)
}
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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))
}
示例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)
}
示例15: LuaDoError
func LuaDoError(L *lua.State, err_str string) {
base.Error().Printf(err_str)
L.PushString(err_str)
L.SetExecutionLimit(1)
}