luar.go
func copyTableToSlice(L *lua.State, idx int, v reflect.Value, visited map[uintptr]reflect.Value) (status error) {
	t := v.Type()
	n := int(L.ObjLen(idx))

	// Adjust the length of the array/slice.
	if n > v.Len() {
		if t.Kind() == reflect.Array {
			n = v.Len()
		} else {
			// Slice
			v.Set(reflect.MakeSlice(t, n, n))
		}
	} else if n < v.Len() {
		if t.Kind() == reflect.Array {
			// Nullify remaining elements.
			for i := n; i < v.Len(); i++ {
				v.Index(i).Set(reflect.Zero(t.Elem()))
			}
		} else {
			// Slice
			v.SetLen(n)
		}
	}

	// Do not add empty slices to the list of visited elements.
	// The empty Lua table is a single instance object and gets re-used across maps, slices and others.
	// Arrays cannot be cyclic since the interface type will ask for slices.
	if n > 0 && t.Kind() != reflect.Array {
		ptr := L.ToPointer(idx)
		visited[ptr] = v
	}

	te := t.Elem()
	for i := 1; i <= n; i++ {
		L.RawGeti(idx, i)
		val := reflect.New(te).Elem()
		err := luaToGo(L, -1, val, visited)
		if err != nil {
			status = ErrTableConv
			L.Pop(1)
			continue
		}
		v.Index(i - 1).Set(val)
		L.Pop(1)
	}

	return
}
func copyTableToSlice(L *lua.State, idx int, v reflect.Value, visited map[uintptr]reflect.Value) (status error) {
	t := v.Type()
	n := int(L.ObjLen(idx))

	// Adjust the length of the array/slice.
	if n > v.Len() {
		if t.Kind() == reflect.Array {
			n = v.Len()
		} else {
			// Slice
			v.Set(reflect.MakeSlice(t, n, n))
		}
	} else if n < v.Len() {
		if t.Kind() == reflect.Array {
			// Nullify remaining elements.
			for i := n; i < v.Len(); i++ {
				v.Index(i).Set(reflect.Zero(t.Elem()))
			}
		} else {
			// Slice
			v.SetLen(n)
		}
	}

	// Do not add empty slices to the list of visited elements.
	// The empty Lua table is a single instance object and gets re-used across maps, slices and others.
	// Arrays cannot be cyclic since the interface type will ask for slices.
	if n > 0 && t.Kind() != reflect.Array {
		ptr := L.ToPointer(idx)
		visited[ptr] = v
	}

	te := t.Elem()
	for i := 1; i <= n; i++ {
		L.RawGeti(idx, i)
		val := reflect.New(te).Elem()
		err := luaToGo(L, -1, val, visited)
		if err != nil {
			status = ErrTableConv
			L.Pop(1)
			continue
		}
		v.Index(i - 1).Set(val)
		L.Pop(1)
	}

	return
}
// Also for arrays. TODO: Create special function for arrays?