MCPcopy Create free account
hub / github.com/go-python/gopy / genVarSetter

Method genVarSetter

bind/gen_varconst.go:78–116  ·  view source on GitHub ↗
(v *Var)

Source from the content-addressed store, hash-verified

76}
77
78func (g *pyGen) genVarSetter(v *Var) {
79 gopkg := g.pkg.Name()
80 pkgname := g.cfg.Name
81 cgoFn := fmt.Sprintf("Set_%s", v.Name())
82 if g.cfg.RenameCase {
83 cgoFn = toSnakeCase(cgoFn)
84 }
85 qCgoFn := gopkg + "_" + cgoFn
86 qFn := "_" + pkgname + "." + qCgoFn
87 qVn := gopkg + "." + v.Name()
88
89 g.pywrap.Printf("def %s(value):\n", cgoFn)
90 g.pywrap.Indent()
91 g.pywrap.Printf("%s\n%s Sets Go Variable: %s\n%s\n%s\n", `"""`, cgoFn, qVn, v.doc, `"""`)
92 g.pywrap.Printf("if isinstance(value, go.GoClass):\n")
93 g.pywrap.Indent()
94 g.pywrap.Printf("%s(value.handle)\n", qFn)
95 g.pywrap.Outdent()
96 g.pywrap.Printf("else:\n")
97 g.pywrap.Indent()
98 g.pywrap.Printf("%s(value)\n", qFn)
99 g.pywrap.Outdent()
100 g.pywrap.Outdent()
101 g.pywrap.Printf("\n")
102
103 g.gofile.Printf("//export %s\n", qCgoFn)
104 g.gofile.Printf("func %s(val %s) {\n", qCgoFn, v.sym.cgoname)
105 g.gofile.Indent()
106 if v.sym.py2go != "" {
107 g.gofile.Printf("%s = %s(val)%s", qVn, v.sym.py2go, v.sym.py2goParenEx)
108 } else {
109 g.gofile.Printf("%s = val", qVn)
110 }
111 g.gofile.Printf("\n")
112 g.gofile.Outdent()
113 g.gofile.Printf("}\n\n")
114
115 g.pybuild.Printf("mod.add_function('%s', None, [param('%s', 'val')])\n", qCgoFn, v.sym.cpyname)
116}
117
118func (g *pyGen) genConstValue(c *Const) {
119 // constants go directly into wrapper as-is

Callers 1

genVarMethod · 0.95

Calls 5

toSnakeCaseFunction · 0.85
PrintfMethod · 0.80
IndentMethod · 0.80
OutdentMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected