本文整理汇总了Golang中github.com/xenith-studios/golua.State.PushString方法的典型用法代码示例。如果您正苦于以下问题:Golang State.PushString方法的具体用法?Golang State.PushString怎么用?Golang State.PushString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xenith-studios/golua.State
的用法示例。
在下文中一共展示了State.PushString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LuaPushSmartFunctionTable
func LuaPushSmartFunctionTable(L *lua.State, ft FunctionTable) {
// Copy it just in case - I can't imagine someone changing it after passing
// it to this function, but I don't want to take any chances.
myft := make(FunctionTable)
for n, f := range ft {
myft[n] = f
}
names := make([]string, len(myft))[0:0]
for name := range myft {
names = append(names, name)
}
sort.Strings(names)
valid_selectors := "["
for i, name := range names {
if i > 0 {
valid_selectors += ", "
}
valid_selectors += fmt.Sprintf("'%s'", name)
}
valid_selectors += "]."
L.NewTable()
L.PushString("__index")
L.PushGoFunctionAsCFunction(func(L *lua.State) int {
name := L.ToString(-1)
if f, ok := myft[name]; ok {
f()
} else {
base.Error().Printf("'%s' is not a valid selector, valid seletors are %s", name, valid_selectors)
L.PushNil()
}
return 1
})
L.SetTable(-3)
}
示例2: 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)
}
示例3: LuaPushRoom
func LuaPushRoom(L *lua.State, game *Game, room *house.Room) {
for fi, f := range game.House.Floors {
for ri, r := range f.Rooms {
if r == room {
L.NewTable()
L.PushString("type")
L.PushString("room")
L.SetTable(-3)
L.PushString("floor")
L.PushInteger(fi)
L.SetTable(-3)
L.PushString("room")
L.PushInteger(ri)
L.SetTable(-3)
L.PushString("Pos")
LuaPushPoint(L, room.X, room.Y)
L.SetTable(-3)
L.PushString("Dims")
LuaPushDims(L, room.Size.Dx, room.Size.Dy)
L.SetTable(-3)
return
}
}
}
L.PushNil()
}
示例4: main
func main() {
var L *golua.State
L = golua.NewState()
L.OpenLibs()
L.GetField(golua.LUA_GLOBALSINDEX, "print")
L.PushString("Hello World!")
L.Call(1, 0)
L.PushGoFunction(test)
L.PushGoFunction(test)
L.PushGoFunction(test)
L.PushGoFunction(test)
L.PushGoFunction(test2)
L.PushInteger(42)
L.Call(1, 0)
L.Call(0, 0)
L.Call(0, 0)
L.Call(0, 0)
L.Close()
}
示例5: LuaPushPoint
func LuaPushPoint(L *lua.State, x, y int) {
L.NewTable()
L.PushString("X")
L.PushInteger(x)
L.SetTable(-3)
L.PushString("Y")
L.PushInteger(y)
L.SetTable(-3)
}
示例6: LuaPushDims
func LuaPushDims(L *lua.State, dx, dy int) {
L.NewTable()
L.PushString("Dx")
L.PushInteger(dx)
L.SetTable(-3)
L.PushString("Dy")
L.PushInteger(dy)
L.SetTable(-3)
}
示例7: 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)
}
示例8: 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)
}
示例9: 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]
}
示例10: LuaToPoint
func LuaToPoint(L *lua.State, pos int) (x, y int) {
L.PushString("X")
L.GetTable(pos - 1)
x = L.ToInteger(-1)
L.Pop(1)
L.PushString("Y")
L.GetTable(pos - 1)
y = L.ToInteger(-1)
L.Pop(1)
return
}
示例11: 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()
}
示例12: LuaIsEntity
func LuaIsEntity(L *lua.State, index int) bool {
L.PushString("type")
L.GetTable(index - 1)
if L.IsNil(-1) {
L.Pop(1)
return false
}
if L.ToString(-1) == "Entity" {
L.Pop(1)
return true
}
L.Pop(1)
return false
}
示例13: Push
func (bae BasicActionExec) Push(L *lua.State, g *Game) {
ent := g.EntityById(bae.Ent)
if bae.Index < 0 || bae.Index >= len(ent.Actions) {
base.Error().Printf("Tried to push an exec for an invalid action index: '%s' %d.", ent.Name)
L.PushNil()
return
}
L.NewTable()
L.PushString("Action")
ent.Actions[bae.Index].Push(L)
L.SetTable(-3)
L.PushString("Ent")
LuaPushEntity(L, ent)
L.SetTable(-3)
}
示例14: Push
func (exec *moveExec) Push(L *lua.State, g *game.Game) {
exec.BasicActionExec.Push(L, g)
if L.IsNil(-1) {
return
}
L.PushString("Path")
L.NewTable()
for i := range exec.Path {
L.PushInteger(i + 1)
_, x, y := g.FromVertex(exec.Path[i])
game.LuaPushPoint(L, x, y)
L.SetTable(-3)
}
L.SetTable(-3)
}
示例15: 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
}