本文整理汇总了Golang中github.com/aarzilli/golua/lua.State.NewTable方法的典型用法代码示例。如果您正苦于以下问题:Golang State.NewTable方法的具体用法?Golang State.NewTable怎么用?Golang State.NewTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aarzilli/golua/lua.State
的用法示例。
在下文中一共展示了State.NewTable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: register
func register(L *lua.State, table string, values Map, convertFun bool) {
pop := true
if table == "*" {
pop = false
} else if len(table) > 0 {
L.GetGlobal(table)
if L.IsNil(-1) {
L.NewTable()
L.SetGlobal(table)
L.GetGlobal(table)
}
} else {
L.GetGlobal("_G")
}
for name, val := range values {
t := reflect.TypeOf(val)
if t.Kind() == reflect.Func {
if convertFun {
L.PushGoFunction(GoLuaFunc(L, val))
} else {
lf := val.(func(*lua.State) int)
L.PushGoFunction(lf)
}
} else {
GoToLua(L, t, valueOf(val), false)
}
L.SetField(-2, name)
}
if pop {
L.Pop(1)
}
}
示例2: 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)
}
示例3: initializeProxies
func initializeProxies(L *lua.State) {
flagValue := func() {
L.SetMetaMethod("__tostring", proxy__tostring)
L.SetMetaMethod("__gc", proxy__gc)
L.SetMetaMethod("__eq", proxy__eq)
L.PushBoolean(true)
L.SetField(-2, "luago.value")
L.Pop(1)
}
L.NewMetaTable(cSLICE_META)
L.SetMetaMethod("__index", slice__index)
L.SetMetaMethod("__newindex", slice__newindex)
L.SetMetaMethod("__len", slicemap__len)
L.SetMetaMethod("__ipairs", slice__ipairs)
flagValue()
L.NewMetaTable(cMAP_META)
L.SetMetaMethod("__index", map__index)
L.SetMetaMethod("__newindex", map__newindex)
L.SetMetaMethod("__len", slicemap__len)
L.SetMetaMethod("__pairs", map__pairs)
flagValue()
L.NewMetaTable(cSTRUCT_META)
L.SetMetaMethod("__index", struct__index)
L.SetMetaMethod("__newindex", struct__newindex)
flagValue()
L.NewMetaTable(cINTERFACE_META)
L.SetMetaMethod("__index", interface__index)
flagValue()
L.NewMetaTable(cCHANNEL_META)
//~ RegisterFunctions(L,"*",FMap {
//~ "Send":channel_send,
//~ "Recv":channel_recv,
//~ })
L.NewTable()
L.PushGoFunction(channel_send)
L.SetField(-2, "Send")
L.PushGoFunction(channel_recv)
L.SetField(-2, "Recv")
L.SetField(-2, "__index")
flagValue()
}
示例4: Register
// Register makes a number of Go values available in Lua code.
// 'values' is a map of strings to Go values.
//
// - If table is non-nil, then create or reuse a global table of that name and
// put the values in it.
//
// - If table is '' then put the values in the global table (_G).
//
// - If table is '*' then assume that the table is already on the stack.
func Register(L *lua.State, table string, values Map) {
pop := true
if table == "*" {
pop = false
} else if len(table) > 0 {
L.GetGlobal(table)
if L.IsNil(-1) {
L.NewTable()
L.SetGlobal(table)
L.GetGlobal(table)
}
} else {
L.GetGlobal("_G")
}
for name, val := range values {
GoToLua(L, nil, reflect.ValueOf(val), false)
L.SetField(-2, name)
}
if pop {
L.Pop(1)
}
}
示例5: register
func register(L *lua.State, table string, values Map, convertFun bool) {
pop := true
if table == "*" {
pop = false
} else if len(table) > 0 {
L.GetGlobal(table)
if L.IsNil(-1) {
L.NewTable()
L.SetGlobal(table)
L.GetGlobal(table)
}
} else {
L.GetGlobal("_G")
}
for name, val := range values {
t := reflect.TypeOf(val)
if t.Kind() == reflect.Func {
if convertFun {
L.PushGoFunction(GoLuaFunc(L, val))
} else {
lf := val.(func(*lua.State) int)
L.PushGoFunction(lf)
}
} else {
GoToLua(L, t, valueOf(val), false)
}
L.SetField(-2, name)
if t.Kind() == reflect.Func {
var lf func(*lua.State) int
if convertFun {
lf = GoLuaFunc(L, val)
} else {
lf = val.(func(*lua.State) int)
}
L.PushGoFunction(func(L *lua.State) (ret int) {
defer func() {
if err2 := recover(); err2 != nil {
GoToLua(L, typeof(err2), valueOf(err2), false)
ret = 1
return
}
}()
ret = lf(L)
pos := L.GetTop() - ret + 1
L.PushNil()
L.Insert(pos)
for i := 0; i < L.GetTop(); i++ {
fmt.Println(L.Typename(int(L.Type(i + 1))))
}
return ret + 1
})
L.SetField(-2, "safe_"+name)
}
}
if pop {
L.Pop(1)
}
}