gopy
gopy copied to clipboard
struct constructor __init__ method accepts int args as handles for object fields
in bind/gen_struct.go -- need some additional type checking logic on that, which also allows valid handles..
still a todo it seems -- here's the relevant code:
for i := 0; i < numFields; i++ {
f := s.Struct().Field(i)
if _, err := isPyCompatField(f); err != nil {
continue
}
// NOTE: this will accept int args for any handles / object fields so
// some kind of additional type-checking logic to prevent that in a way
// that also allows valid handles to be used as required. This is
// achieved in the per-field setters (see below) with checks to ensure
// that a struct field that is a gopy managed object is only
// assigned gopy managed objects. Fields of basic types (e.g int, string)
// etc can be assigned to directly.
g.pywrap.Printf("if %[1]d < len(args):\n", i)
g.pywrap.Indent()
g.pywrap.Printf("self.%s = args[%d]\n", f.Name(), i)
g.pywrap.Outdent()
g.pywrap.Printf("if %[1]q in kwargs:\n", f.Name())
g.pywrap.Indent()
g.pywrap.Printf("self.%[1]s = kwargs[%[1]q]\n", f.Name())
g.pywrap.Outdent()
}