From eb5fcfc8802169f1b6b096135351ad27f48e2d02 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 11 Aug 2024 16:37:06 +1200 Subject: [PATCH] genbindings: add private Go ctor for use with C types --- cmd/genbindings/emitgo.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/genbindings/emitgo.go b/cmd/genbindings/emitgo.go index 58dd9043..78492586 100644 --- a/cmd/genbindings/emitgo.go +++ b/cmd/genbindings/emitgo.go @@ -117,13 +117,20 @@ import "C" localInit += ", " + base + ": " + base + "{h: ret}" } + ret.WriteString(` + func new` + c.ClassName + `(h C.P` + c.ClassName + `) { + return &` + c.ClassName + `{` + localInit + `} + } + + `) + for i, ctor := range c.Ctors { preamble, forwarding := emitParametersGo2CABIForwarding(ctor) ret.WriteString(` // New` + c.ClassName + maybeSuffix(i) + ` constructs a new ` + c.ClassName + ` object. func New` + c.ClassName + maybeSuffix(i) + `(` + emitParametersGo(ctor.Parameters) + `) { ` + preamble + ` ret := C.` + c.ClassName + `_new` + maybeSuffix(i) + `(` + forwarding + `) - return &` + c.ClassName + `{` + localInit + `} + return new` + c.ClassName + `(h) } `)