go-python / gopy

gopy generates a CPython extension module from a go package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't return a slice of slices ([][]bool)

moritz157 opened this issue · comments

I wanted to pass a slice of slices of boolean values ([][]bool). I would assume that this could simply be done like this:

func GetEmptyMatrix(xSize int, ySize int) [][]bool {
	result := [][]bool{}

	for i := 0; i < xSize; i++ {
		result = append(result, []bool{})
		for j := 0; j < ySize; j++ {
			result[i] = append(result[i], false)
		}
	}

	return result
}

In Python I then simply called the function:

from out import matrix

matrix.GetEmptyMatrix(4,4)

However, this failed with the following error: panic: interface conversion: interface {} is []bool, not *[]bool

Is passing a slice of slices generally not supported or do I have to do it in a different way (like passing a slice of pointers to slices)? If this is supported, I would suggest to maybe add an example for this because as far as I can see, there is none yet. If I'm just doing it wrong, a hint in the right direction would be greatly appreciated :)

This problem has similarities to this.

I'm assuming this is now fixed by #350 unless someone tells me otherwise. And if someone could write a test to confirm, that would be most appreciated (@EvanOman ?)

@rcoreilly No, my previous PR did not fix slices, only maps

However I just added #351 which fixes this issue and adds a test based on the example from @moritz157