本文整理匯總了Golang中github.com/aarzilli/golua/lua.State.PushValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.PushValue方法的具體用法?Golang State.PushValue怎麽用?Golang State.PushValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aarzilli/golua/lua.State
的用法示例。
在下文中一共展示了State.PushValue方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GoLua
func GoLua(L *lua.State) int {
go func() {
LT := L.NewThread()
L.PushValue(1)
lua.XMove(L, LT, 1)
res := LT.Resume(0)
for res != 0 {
if res == 2 {
emsg := LT.ToString(-1)
RaiseError(LT, emsg)
}
ch, t := valueOfProxy(LT, -2)
if LT.ToBoolean(-1) { // send on a channel
val := luaToGoValue(LT, t.Elem(), -3)
ch.Send(val)
res = LT.Resume(0)
} else { // receive on a channel
val, ok := ch.Recv()
GoToLua(LT, t.Elem(), val, false)
LT.PushBoolean(ok)
res = LT.Resume(2)
}
}
}()
return 0
}
示例2: channel_send
func channel_send(L *lua.State) int {
L.PushValue(2)
L.PushValue(1)
L.PushBoolean(true)
return L.Yield(3)
//~ ch,t := valueOfProxy(L,1)
//~ val := valueOf(LuaToGo(L, t.Elem(),2))
//~ ch.Send(val)
//~ return 0
}
示例3: channel_recv
func channel_recv(L *lua.State) int {
L.PushValue(1)
L.PushBoolean(false)
return L.Yield(2)
//~ ch,t := valueOfProxy(L,1)
//~ L.Yield(0)
//~ val,ok := ch.Recv()
//~ GoToLua(L,t.Elem(),val)
//~ L.PushBoolean(ok)
//~ L.Resume(0)
//~ return 2
}
示例4: Lookup
// look up a Lua value by its full name. If idx is 0, then this name
// is assumed to start in the global table, e.g. "string.gsub".
// With non-zero idx, can be used to look up subfields of a table
func Lookup(L *lua.State, path string, idx int) {
parts := strings.Split(path, ".")
if idx != 0 {
L.PushValue(idx)
} else {
L.GetGlobal("_G")
}
for _, field := range parts {
L.GetField(-1, field)
L.Remove(-2) // remove table
}
}
示例5: ProxyPairs
// ProxyPairs implements Lua 5.2 'pairs' functions.
// It respects the __pairs metamethod.
//
// It is only useful for compatibility with Lua 5.1.
func ProxyPairs(L *lua.State) int {
// See Lua >=5.2 source code.
if L.GetMetaField(1, "__pairs") {
L.PushValue(1)
L.Call(1, 3)
return 3
}
L.CheckType(1, lua.LUA_TTABLE)
L.PushGoFunction(pairsAux)
L.PushValue(1)
L.PushNil()
return 3
}
示例6: NewLuaObject
// A new LuaObject from stack index.
func NewLuaObject(L *lua.State, idx int) *LuaObject {
tp := L.LTypename(idx)
L.PushValue(idx)
ref := L.Ref(lua.LUA_REGISTRYINDEX)
return &LuaObject{L, ref, tp}
}