本文整理汇总了Golang中github.com/aarzilli/golua/lua.State.SetTable方法的典型用法代码示例。如果您正苦于以下问题:Golang State.SetTable方法的具体用法?Golang State.SetTable怎么用?Golang State.SetTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aarzilli/golua/lua.State
的用法示例。
在下文中一共展示了State.SetTable方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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)
}
}
示例4: MessThingContents
func MessThingContents(state *lua.State, thing *Thing) int {
// make a new table
state.CreateTable(len(thing.Contents), 0) // ( -- tbl )
// for each content add a new lua-space Thing
for i, contentId := range thing.Contents {
state.PushInteger(int64(i))
pushValue(state, contentId)
state.SetTable(-3) // ( tbl key val -- tbl )
} // ( tbl -- tbl )
return 1
}
示例5: sandboxCompile
func sandboxCompile(L *lua.State, registryIndex string, name, code string) {
L.PushString(registryIndex)
L.GetTable(lua.LUA_REGISTRYINDEX)
L.PushString(name)
err := L.LoadString(code)
if err != 0 {
log.Fatalf("%s: %s", name, L.ToString(-1))
L.Pop(2)
} else {
L.SetTable(-3)
}
}
示例6: CopySliceToTable
// copy a Go slice to a Lua table
func CopySliceToTable(L *lua.State, vslice reflect.Value) int {
if vslice.IsValid() && vslice.Type().Kind() == reflect.Slice {
n := vslice.Len()
L.CreateTable(n, 0)
for i := 0; i < n; i++ {
L.PushInteger(int64(i + 1))
GoToLua(L, nil, vslice.Index(i))
L.SetTable(-3)
}
return 1
} else {
L.PushNil()
L.PushString("not a slice!")
}
return 2
}
示例7: CopyMapToTable
// copy a Go map to a Lua table
func CopyMapToTable(L *lua.State, vmap reflect.Value) int {
if vmap.IsValid() && vmap.Type().Kind() == reflect.Map {
n := vmap.Len()
L.CreateTable(0, n)
for _, key := range vmap.MapKeys() {
val := vmap.MapIndex(key)
GoToLua(L, nil, key)
GoToLua(L, nil, val)
L.SetTable(-3)
}
return 1
} else {
L.PushNil()
L.PushString("not a map!")
}
return 2
}
示例8: copyMapToTable
func copyMapToTable(L *lua.State, vmap reflect.Value, visited visitor) int {
if vmap.IsValid() && vmap.Type().Kind() == reflect.Map {
n := vmap.Len()
L.CreateTable(0, n)
visited.mark(vmap)
for _, key := range vmap.MapKeys() {
v := vmap.MapIndex(key)
goToLua(L, nil, key, false, visited)
if isNil(v) {
v = nullv
}
goToLua(L, nil, v, true, visited)
L.SetTable(-3)
}
return 1
}
L.PushNil()
L.PushString("not a map!")
return 2
}
示例9: CopyStructToTable
// Copy a Go struct to a Lua table. nils in both slices and structs
// are represented as luar.null. Defines luar.struct2table
// Use tags to set field names.
func CopyStructToTable(L *lua.State, vstruct reflect.Value) int {
if vstruct.IsValid() && vstruct.Type().Kind() == reflect.Struct {
n := vstruct.NumField()
L.CreateTable(n, 0)
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)
v := vstruct.Field(i)
GoToLua(L, nil, v, true)
L.SetTable(-3)
}
return 1
} else {
L.PushNil()
L.PushString("not a struct!")
}
return 2
}
示例10: SetTableIntString
func SetTableIntString(L *lua.State, idx int64, value string) {
L.PushInteger(idx)
L.PushString(value)
L.SetTable(-3)
}
示例11: SetTableInt
func SetTableInt(L *lua.State, name string, value int64) {
// Remember to check stack for 2 extra locations
L.PushString(name)
L.PushInteger(value)
L.SetTable(-3)
}