本文整理汇总了Golang中github.com/xenith-studios/golua.State.PushNil方法的典型用法代码示例。如果您正苦于以下问题:Golang State.PushNil方法的具体用法?Golang State.PushNil怎么用?Golang State.PushNil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/xenith-studios/golua.State
的用法示例。
在下文中一共展示了State.PushNil方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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()
}
示例2: 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()
}
示例3: 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)
}
示例4: 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)
}
示例5: 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))
}
示例6: 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
}
示例7: main
func main() {
var L *lua.State
L = lua.NewState()
defer L.Close()
L.OpenLibs()
currentPanicf := L.AtPanic(nil)
currentPanicf = L.AtPanic(currentPanicf)
newPanic := func(L1 *lua.State) int {
fmt.Println("I AM PANICKING!!!")
return currentPanicf(L1)
}
L.AtPanic(newPanic)
//force a panic
L.PushNil()
L.Call(0, 0)
}
示例8: 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)
}
示例9: 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)
}
//.........这里部分代码省略.........
示例10: LuaPushEntity
// Pushes an entity onto the stack, it is a table containing the following:
// e.id -> EntityId of this entity
// e.name -> Name as displayed to the user
// e.gear_options -> Table mapping gear to icon for all available gear
// e.gear -> Name of the selected gear, nil if none is selected
// e.actions -> Array of actions this entity has available
func LuaPushEntity(L *lua.State, ent *Entity) {
if ent == nil {
L.PushNil()
return
}
// id and Name can be added to the ent table as static data since they
// never change.
L.NewTable()
L.PushString("Name")
L.PushString(ent.Name)
L.SetTable(-3)
L.PushString("id")
L.PushInteger(int(ent.Id))
L.SetTable(-3)
L.PushString("type")
L.PushString("Entity")
L.SetTable(-3)
// Meta table for the Entity so that any dynamic data is generated
// on-the-fly
LuaPushSmartFunctionTable(L, FunctionTable{
"Conditions": func() {
L.NewTable()
for _, condition := range ent.Stats.ConditionNames() {
L.PushString(condition)
L.PushBoolean(true)
L.SetTable(-3)
}
},
"Side": func() {
L.NewTable()
sides := map[string]Side{
"Denizen": SideHaunt,
"Intruder": SideExplorers,
"Npc": SideNpc,
"Object": SideObject,
}
for str, side := range sides {
L.PushString(str)
L.PushBoolean(ent.Side() == side)
L.SetTable(-3)
}
},
"State": func() {
L.PushString(ent.Sprite().State())
},
"Master": func() {
L.NewTable()
for key, val := range ent.Ai_data {
L.PushString(key)
L.PushString(val)
L.SetTable(-3)
}
},
"GearOptions": func() {
L.NewTable()
if ent.ExplorerEnt != nil {
for _, gear_name := range ent.ExplorerEnt.Gear_names {
var g Gear
g.Defname = gear_name
base.GetObject("gear", &g)
L.PushString(gear_name)
L.PushString(g.Large_icon.Path.String())
L.SetTable(-3)
}
}
},
"Gear": func() {
if ent.ExplorerEnt != nil && ent.ExplorerEnt.Gear != nil {
L.PushString(ent.ExplorerEnt.Gear.Name)
} else {
L.PushNil()
}
},
"Actions": func() {
L.NewTable()
for _, action := range ent.Actions {
L.PushString(action.String())
action.Push(L)
L.SetTable(-3)
}
},
"Pos": func() {
x, y := ent.Pos()
LuaPushPoint(L, x, y)
},
"Corpus": func() {
L.PushInteger(ent.Stats.Corpus())
},
"Ego": func() {
L.PushInteger(ent.Stats.Ego())
},
"HpCur": func() {
L.PushInteger(ent.Stats.HpCur())
//.........这里部分代码省略.........