示例#1
0
文件: luar.go 项目: kdar/morphgen
// 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
}
示例#2
0
文件: luar.go 项目: kdar/morphgen
func slicemap__len(L *lua.State) int {
	val, _ := valueOfProxy(L, 1)
	L.PushInteger(int64(val.Len()))
	return 1
}