本文整理匯總了Golang中github.com/aarzilli/golua/lua.State.PushNil方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.PushNil方法的具體用法?Golang State.PushNil怎麽用?Golang State.PushNil使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aarzilli/golua/lua.State
的用法示例。
在下文中一共展示了State.PushNil方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CopyTableToStruct
// Copy matching Lua table entries to a struct, given the struct type
// and the index on the Lua stack.
func CopyTableToStruct(L *lua.State, t reflect.Type, idx int) interface{} {
was_ptr := t.Kind() == reflect.Ptr
if was_ptr {
t = t.Elem()
}
s := reflect.New(t) // T -> *T
ref := s.Elem()
L.PushNil()
if idx < 0 {
idx--
}
for L.Next(idx) != 0 {
key := L.ToString(-2)
f := ref.FieldByName(strings.Title(key))
if f.IsValid() {
val := luaToGoValue(L, f.Type(), -1)
f.Set(val)
}
L.Pop(1)
}
if was_ptr {
return s.Interface()
}
return s.Elem().Interface()
}
示例2: copySliceToTable
// Also for arrays.
func copySliceToTable(L *lua.State, vslice reflect.Value, visited visitor) int {
ref := vslice
for vslice.Kind() == reflect.Ptr {
// For arrays.
vslice = vslice.Elem()
}
if vslice.IsValid() && (vslice.Kind() == reflect.Slice || vslice.Kind() == reflect.Array) {
n := vslice.Len()
L.CreateTable(n, 0)
if vslice.Kind() == reflect.Slice {
visited.mark(vslice)
} else if ref.Kind() == reflect.Ptr {
visited.mark(ref)
}
for i := 0; i < n; i++ {
L.PushInteger(int64(i + 1))
v := vslice.Index(i)
if isNil(v) {
v = nullv
}
goToLua(L, nil, v, true, visited)
L.SetTable(-3)
}
return 1
}
L.PushNil()
L.PushString("not a slice/array")
return 2
}
示例3: popMap
func popMap(L *lua.State) map[string]interface{} {
m := make(map[string]interface{})
L.PushNil()
for L.Next(-2) != 0 {
if L.IsString(-2) {
var v interface{}
if L.IsBoolean(-1) {
v = L.ToBoolean(-1)
} else if L.IsNumber(-1) {
var t float64
t = L.ToNumber(-1)
if t == float64(int64(t)) {
v = int(t)
} else {
v = t
}
} else if L.IsString(-1) {
v = L.ToString(-1)
} else if L.IsNil(-1) {
v = nil
} else if L.IsTable(-1) {
v = popMap(L)
}
m[L.ToString(-2)] = v
}
L.Pop(1)
}
return m
}
示例4: pushMap
func pushMap(L *lua.State, m map[string]interface{}, lower bool) {
L.CreateTable(0, len(m))
for k, v := range m {
if lower {
L.PushString(strings.ToLower(k))
} else {
L.PushString(k)
}
switch t := v.(type) {
case string:
L.PushString(t)
case int64:
L.PushInteger(t)
case int:
L.PushInteger(int64(t))
case float64:
L.PushNumber(t)
case bool:
L.PushBoolean(t)
case map[string]interface{}:
pushMap(L, t, false)
default:
L.PushNil()
}
L.SetTable(-3)
}
}
示例5: copyStructToTable
func copyStructToTable(L *lua.State, vstruct reflect.Value, visited visitor) int {
// If 'vstruct' is a pointer to struct, use the pointer to mark as visited.
ref := vstruct
for vstruct.Kind() == reflect.Ptr {
vstruct = vstruct.Elem()
}
if vstruct.IsValid() && vstruct.Type().Kind() == reflect.Struct {
n := vstruct.NumField()
L.CreateTable(n, 0)
if ref.Kind() == reflect.Ptr {
visited.mark(ref)
}
for i := 0; i < n; i++ {
st := vstruct.Type()
field := st.Field(i)
key := field.Name
tag := field.Tag.Get("lua")
if tag != "" {
key = tag
}
goToLua(L, nil, reflect.ValueOf(key), true, visited)
v := vstruct.Field(i)
goToLua(L, nil, v, true, visited)
L.SetTable(-3)
}
return 1
}
L.PushNil()
L.PushString("not a struct")
return 2
}
示例6: copyTableToMap
func copyTableToMap(L *lua.State, t reflect.Type, idx int, visited map[uintptr]interface{}) interface{} {
if t == nil {
t = tmap
}
te, tk := t.Elem(), t.Key()
m := reflect.MakeMap(t)
// See copyTableToSlice.
ptr := L.ToPointer(idx)
if !luaIsEmpty(L, idx) {
visited[ptr] = m.Interface()
}
L.PushNil()
if idx < 0 {
idx--
}
for L.Next(idx) != 0 {
// key at -2, value at -1
key := reflect.ValueOf(luaToGo(L, tk, -2, visited))
val := reflect.ValueOf(luaToGo(L, te, -1, visited))
if val.Interface() == nullv.Interface() {
val = reflect.Zero(te)
}
m.SetMapIndex(key, val)
L.Pop(1)
}
return m.Interface()
}
示例7: outputNumbersToStrings
func outputNumbersToStrings(L *lua.State) {
L.GetGlobal("output")
if !L.IsTable(-1) {
L.NewTable()
L.SetGlobal("output")
}
L.GetField(-1, "tags")
if L.IsTable(-1) {
// First key.
L.PushNil()
for L.Next(-2) != 0 {
// Use 'key' at index -2 and 'value' at index -1.
if L.IsString(-2) && L.IsString(-1) {
// Convert numbers to strings.
L.ToString(-1)
L.SetField(-3, L.ToString(-2))
} else {
// Remove 'value' and keep 'key' for next iteration.
L.Pop(1)
}
}
}
L.Pop(1)
L.Pop(1)
}
示例8: proxyType
func proxyType(L *lua.State) int {
v := unwrapProxy(L, 1)
if v != nil {
GoToLua(L, nil, valueOf(reflect.TypeOf(v)), false)
} else {
L.PushNil()
}
return 1
}
示例9: pairsAux
func pairsAux(L *lua.State) int {
L.CheckType(1, lua.LUA_TTABLE)
L.SetTop(2) // Create a 2nd argument if there isn't one.
if L.Next(1) != 0 {
return 2
}
L.PushNil()
return 1
}
示例10: Unproxify
// Unproxify converts a proxy to an unproxified Lua value.
//
// Argument: proxy
//
// Returns: value (Lua value)
func Unproxify(L *lua.State) int {
if !isValueProxy(L, 1) {
L.PushNil()
return 1
}
v, _ := valueOfProxy(L, 1)
GoToLua(L, nil, v, true)
return 1
}
示例11: ProxyMethod
// ProxyMethod pushes the proxy method on the stack.
//
// Argument: proxy
//
// Returns: method (function)
func ProxyMethod(L *lua.State) int {
if !isValueProxy(L, 1) {
L.PushNil()
return 1
}
v, _ := valueOfProxy(L, 1)
name := L.ToString(2)
pushGoMethod(L, name, v)
return 1
}
示例12: luaIsEmpty
func luaIsEmpty(L *lua.State, idx int) bool {
L.PushNil()
if idx < 0 {
idx--
}
if L.Next(idx) != 0 {
L.Pop(2)
return false
}
return true
}
示例13: ProxyRaw
// ProxyRaw unproxifies a value.
//
// WARNING: Deprecated, use luar.unproxify instead.
func ProxyRaw(L *lua.State) int {
v := mustUnwrapProxy(L, 1)
val := reflect.ValueOf(v)
tp := predeclaredScalarType(val.Type())
if tp != nil {
val = val.Convert(tp)
GoToLua(L, nil, val, false)
} else {
L.PushNil()
}
return 1
}
示例14: copyTableToStruct
func copyTableToStruct(L *lua.State, t reflect.Type, idx int, visited map[uintptr]interface{}) interface{} {
if t == nil {
RaiseError(L, "type argument must be non-nill")
}
wasPtr := t.Kind() == reflect.Ptr
if wasPtr {
t = t.Elem()
}
s := reflect.New(t) // T -> *T
ref := s.Elem()
// See copyTableToSlice.
ptr := L.ToPointer(idx)
if !luaIsEmpty(L, idx) {
if wasPtr {
visited[ptr] = s.Interface()
} else {
visited[ptr] = s.Elem().Interface()
}
}
// Associate Lua keys with Go fields: tags have priority over matching field
// name.
fields := map[string]string{}
st := ref.Type()
for i := 0; i < ref.NumField(); i++ {
field := st.Field(i)
tag := field.Tag.Get("lua")
if tag != "" {
fields[tag] = field.Name
continue
}
fields[field.Name] = field.Name
}
L.PushNil()
if idx < 0 {
idx--
}
for L.Next(idx) != 0 {
key := L.ToString(-2)
f := ref.FieldByName(fields[key])
if f.CanSet() && f.IsValid() {
val := reflect.ValueOf(luaToGo(L, f.Type(), -1, visited))
f.Set(val)
}
L.Pop(1)
}
if wasPtr {
return s.Interface()
}
return s.Elem().Interface()
}
示例15: ProxyType
// ProxyType pushes the proxy type on the stack.
//
// Argument: proxy
//
// Returns: type (string)
func ProxyType(L *lua.State) int {
if !isValueProxy(L, 1) {
L.PushNil()
return 1
}
v, _ := valueOfProxy(L, 1)
if v.Interface() == nil {
L.PushNil()
return 1
}
GoToLua(L, nil, reflect.ValueOf(v.Type()), false)
return 1
}