detached 1e910b3

Merge pull request #1 from pdf/add_generators

Add generators
commit
1e910b3f3cbbdccb03217890e30e7c7a2bfa6a10
author
Jeroen Wijenbergh · · 2024-01-08 16:35 UTC
committer
GitHub · · 2024-01-08 16:35 UTC
merge of
89b99ee + fd80be9 · diff against the first parent
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
5 files · +172 -45
M internal/gir/pass/pass.go +65 -13
@@ -92,13 +92,32 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
9292 enums[fn] = append(enums[fn], temp)
9393 }
9494
95+ constants := make(map[string][]types.ConstantTemplate)
96+ for _, con := range ns.Constants {
97+ fn := con.FilenameSafe()
98+ files = append(files, fn)
99+ constants[fn] = append(constants[fn], con.Template(ns.Name, p.Types))
100+ }
101+
95102 records := make(map[string][]types.RecordTemplate)
96103 recordLookup := make(map[string]bool)
97104 for _, rec := range ns.Records {
98105 name := util.SnakeToCamel(rec.Name)
99- fields := make([]types.RecordField, len(rec.Fields))
106+ constructors := make([]types.FuncTemplate, len(rec.Constructors))
107+ receivers := make([]types.FuncTemplate, 0, len(rec.Methods))
108+ fields := make([]types.RecordField, 0, len(rec.Fields))
100109 fn := rec.FilenameSafe()
101110 files = append(files, fn)
111+ for i, c := range rec.Constructors {
112+ name := util.SnakeToCamel(c.Name)
113+ constructors[i] = types.FuncTemplate{
114+ Name: name,
115+ CName: c.CIdentifier,
116+ Doc: c.Doc.StringSafe(),
117+ Args: c.Parameters.Template(ns.Name, "", p.Types, c.Throws),
118+ Ret: c.ReturnValue.Template(ns.Name, "", p.Types, c.Throws),
119+ }
120+ }
102121 for _, f := range rec.Fields {
103122 _type := f.Translate(ns.Name, p.Types)
104123 if _type == "" {
@@ -120,10 +139,31 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
120139 Type: _type,
121140 })
122141 }
142+ for _, f := range rec.Methods {
143+ name := util.SnakeToCamel(f.Name)
144+ if name == "" {
145+ name = util.SnakeToCamel(f.CIdentifier)
146+ }
147+ for _, f := range fields {
148+ if f.Name == name {
149+ name = name + "Fn"
150+ break
151+ }
152+ }
153+ receivers = append(receivers, types.FuncTemplate{
154+ Doc: f.Doc.StringSafe(),
155+ Name: name,
156+ CName: f.CIdentifier,
157+ Args: f.Parameters.Template(ns.Name, "", p.Types, f.Throws),
158+ Ret: f.ReturnValue.Template(ns.Name, "", p.Types, f.Throws),
159+ })
160+ }
123161 records[fn] = append(records[fn], types.RecordTemplate{
124- Name: name,
125- Doc: rec.Doc.StringSafe(),
126- Fields: fields,
162+ Name: name,
163+ Doc: rec.Doc.StringSafe(),
164+ Constructors: constructors,
165+ Receivers: receivers,
166+ Fields: fields,
127167 })
128168 recordLookup[name] = true
129169 }
@@ -200,6 +240,7 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
200240 for _, cls := range ns.Classes {
201241 implemented := make(map[string]bool)
202242 constructors := make([]types.FuncTemplate, len(cls.Constructors))
243+ functions := make([]types.FuncTemplate, len(cls.Functions))
203244 fn := cls.FilenameSafe()
204245 files = append(files, fn)
205246
@@ -236,6 +277,16 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
236277 }
237278 }
238279 var interfaces []types.InterfaceTemplate
280+ for i, f := range cls.Functions {
281+ name := fmt.Sprintf("%s%s", util.SnakeToCamel(cls.Name), util.SnakeToCamel(f.Name))
282+ functions[i] = types.FuncTemplate{
283+ Name: name,
284+ CName: f.CIdentifier,
285+ Doc: f.Doc.StringSafe(),
286+ Args: f.Parameters.Template(ns.Name, "", p.Types, f.Throws),
287+ Ret: f.ReturnValue.Template(ns.Name, "", p.Types, f.Throws),
288+ }
289+ }
239290 for _, impl := range cls.Implements {
240291 interfaces = append(interfaces, types.GetInterfaceFuncs(ns.Name, impl.Name, implemented, p.Types))
241292 }
@@ -246,6 +297,7 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
246297 Constructors: constructors,
247298 Receivers: receivers,
248299 Interfaces: interfaces,
300+ Functions: functions,
249301 Signals: signals,
250302 })
251303 }
@@ -263,17 +315,16 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
263315 //}
264316 methods := 0
265317 for _, i := range interfaces[fn] {
266- for range i.Methods {
267- methods += 1
268- }
318+ methods += len(i.Methods)
319+ }
320+ for _, i := range records[fn] {
321+ methods += len(i.Constructors)
322+ methods += len(i.Receivers)
269323 }
270324 for _, i := range classes[fn] {
271- for range i.Constructors {
272- methods += 1
273- }
274- for range i.Receivers {
275- methods += 1
276- }
325+ methods += len(i.Constructors)
326+ methods += len(i.Receivers)
327+ methods += len(i.Functions)
277328 }
278329 // we do not need to add the length of interfaces in here
279330 // as they should only be loaded when there are classes
@@ -288,6 +339,7 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
288339 Callbacks: callbacks[fn],
289340 Records: records[fn],
290341 Enums: enums[fn],
342+ Constants: constants[fn],
291343 Functions: functions[fn],
292344 Interfaces: interfaces[fn],
293345 Classes: classes[fn],
@@ -92,13 +92,32 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
92 enums[fn] = append(enums[fn], temp)92 enums[fn] = append(enums[fn], temp)
93 }93 }
94 94
95+ constants := make(map[string][]types.ConstantTemplate)
96+ for _, con := range ns.Constants {
97+ fn := con.FilenameSafe()
98+ files = append(files, fn)
99+ constants[fn] = append(constants[fn], con.Template(ns.Name, p.Types))
100+ }
101+
95 records := make(map[string][]types.RecordTemplate)102 records := make(map[string][]types.RecordTemplate)
96 recordLookup := make(map[string]bool)103 recordLookup := make(map[string]bool)
97 for _, rec := range ns.Records {104 for _, rec := range ns.Records {
98 name := util.SnakeToCamel(rec.Name)105 name := util.SnakeToCamel(rec.Name)
99- fields := make([]types.RecordField, len(rec.Fields))106+ constructors := make([]types.FuncTemplate, len(rec.Constructors))
107+ receivers := make([]types.FuncTemplate, 0, len(rec.Methods))
108+ fields := make([]types.RecordField, 0, len(rec.Fields))
100 fn := rec.FilenameSafe()109 fn := rec.FilenameSafe()
101 files = append(files, fn)110 files = append(files, fn)
111+ for i, c := range rec.Constructors {
112+ name := util.SnakeToCamel(c.Name)
113+ constructors[i] = types.FuncTemplate{
114+ Name: name,
115+ CName: c.CIdentifier,
116+ Doc: c.Doc.StringSafe(),
117+ Args: c.Parameters.Template(ns.Name, "", p.Types, c.Throws),
118+ Ret: c.ReturnValue.Template(ns.Name, "", p.Types, c.Throws),
119+ }
120+ }
102 for _, f := range rec.Fields {121 for _, f := range rec.Fields {
103 _type := f.Translate(ns.Name, p.Types)122 _type := f.Translate(ns.Name, p.Types)
104 if _type == "" {123 if _type == "" {
@@ -120,10 +139,31 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
120 Type: _type,139 Type: _type,
121 })140 })
122 }141 }
142+ for _, f := range rec.Methods {
143+ name := util.SnakeToCamel(f.Name)
144+ if name == "" {
145+ name = util.SnakeToCamel(f.CIdentifier)
146+ }
147+ for _, f := range fields {
148+ if f.Name == name {
149+ name = name + "Fn"
150+ break
151+ }
152+ }
153+ receivers = append(receivers, types.FuncTemplate{
154+ Doc: f.Doc.StringSafe(),
155+ Name: name,
156+ CName: f.CIdentifier,
157+ Args: f.Parameters.Template(ns.Name, "", p.Types, f.Throws),
158+ Ret: f.ReturnValue.Template(ns.Name, "", p.Types, f.Throws),
159+ })
160+ }
123 records[fn] = append(records[fn], types.RecordTemplate{161 records[fn] = append(records[fn], types.RecordTemplate{
124- Name: name,162+ Name: name,
125- Doc: rec.Doc.StringSafe(),163+ Doc: rec.Doc.StringSafe(),
126- Fields: fields,164+ Constructors: constructors,
165+ Receivers: receivers,
166+ Fields: fields,
127 })167 })
128 recordLookup[name] = true168 recordLookup[name] = true
129 }169 }
@@ -200,6 +240,7 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
200 for _, cls := range ns.Classes {240 for _, cls := range ns.Classes {
201 implemented := make(map[string]bool)241 implemented := make(map[string]bool)
202 constructors := make([]types.FuncTemplate, len(cls.Constructors))242 constructors := make([]types.FuncTemplate, len(cls.Constructors))
243+ functions := make([]types.FuncTemplate, len(cls.Functions))
203 fn := cls.FilenameSafe()244 fn := cls.FilenameSafe()
204 files = append(files, fn)245 files = append(files, fn)
205 246
@@ -236,6 +277,16 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
236 }277 }
237 }278 }
238 var interfaces []types.InterfaceTemplate279 var interfaces []types.InterfaceTemplate
280+ for i, f := range cls.Functions {
281+ name := fmt.Sprintf("%s%s", util.SnakeToCamel(cls.Name), util.SnakeToCamel(f.Name))
282+ functions[i] = types.FuncTemplate{
283+ Name: name,
284+ CName: f.CIdentifier,
285+ Doc: f.Doc.StringSafe(),
286+ Args: f.Parameters.Template(ns.Name, "", p.Types, f.Throws),
287+ Ret: f.ReturnValue.Template(ns.Name, "", p.Types, f.Throws),
288+ }
289+ }
239 for _, impl := range cls.Implements {290 for _, impl := range cls.Implements {
240 interfaces = append(interfaces, types.GetInterfaceFuncs(ns.Name, impl.Name, implemented, p.Types))291 interfaces = append(interfaces, types.GetInterfaceFuncs(ns.Name, impl.Name, implemented, p.Types))
241 }292 }
@@ -246,6 +297,7 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
246 Constructors: constructors,297 Constructors: constructors,
247 Receivers: receivers,298 Receivers: receivers,
248 Interfaces: interfaces,299 Interfaces: interfaces,
300+ Functions: functions,
249 Signals: signals,301 Signals: signals,
250 })302 })
251 }303 }
@@ -263,17 +315,16 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
263 //}315 //}
264 methods := 0316 methods := 0
265 for _, i := range interfaces[fn] {317 for _, i := range interfaces[fn] {
266- for range i.Methods {318+ methods += len(i.Methods)
267- methods += 1319+ }
268- }320+ for _, i := range records[fn] {
321+ methods += len(i.Constructors)
322+ methods += len(i.Receivers)
269 }323 }
270 for _, i := range classes[fn] {324 for _, i := range classes[fn] {
271- for range i.Constructors {325+ methods += len(i.Constructors)
272- methods += 1326+ methods += len(i.Receivers)
273- }327+ methods += len(i.Functions)
274- for range i.Receivers {
275- methods += 1
276- }
277 }328 }
278 // we do not need to add the length of interfaces in here329 // we do not need to add the length of interfaces in here
279 // as they should only be loaded when there are classes330 // as they should only be loaded when there are classes
@@ -288,6 +339,7 @@ func (p *Pass) writeGo(r types.Repository, gotemp *template.Template, dir string
288 Callbacks: callbacks[fn],339 Callbacks: callbacks[fn],
289 Records: records[fn],340 Records: records[fn],
290 Enums: enums[fn],341 Enums: enums[fn],
342+ Constants: constants[fn],
291 Functions: functions[fn],343 Functions: functions[fn],
292 Interfaces: interfaces[fn],344 Interfaces: interfaces[fn],
293 Classes: classes[fn],345 Classes: classes[fn],
M internal/gir/types/template.go +21 -0
@@ -174,6 +174,12 @@ type RecordTemplate struct {
174174 // Doc is the documentation of the alias
175175 Doc string
176176
177+ // Constructors is the slice of functions that create the class struct
178+ Constructors []FuncTemplate
179+
180+ // Receivers is the slice of functions that have value receivers to the struct
181+ Receivers []FuncTemplate
182+
177183 // Fields is the list of record fields
178184 Fields []RecordField
179185 }
@@ -196,6 +202,17 @@ type EnumTemplate struct {
196202 Values []enumValues
197203 }
198204
205+type ConstantTemplate struct {
206+ // Name is the name of the constant
207+ Name string
208+ // Doc is the documentation for the constant
209+ Doc string
210+ // Type is the Go type for the constant
211+ Type string
212+ // Values are the list of values for the constant
213+ Value string
214+}
215+
199216 type funcRetTemplate struct {
200217 // Raw is the raw value for the underlying purego function
201218 Raw string
@@ -342,6 +359,8 @@ type ClassTemplate struct {
342359 Receivers []FuncTemplate
343360 // Interfaces are receiver methods that are implemented because it needs to satisfy a certain interface
344361 Interfaces []InterfaceTemplate
362+ // Functions are the Go function declarations
363+ Functions []FuncTemplate
345364 // Signals are helpers for ConnectX receivers
346365 Signals []SignalsTemplate
347366 }
@@ -372,6 +391,8 @@ type TemplateArg struct {
372391 Callbacks []CallbackTemplate
373392 // Enums are enumerations declared as const ... .... = ....
374393 Enums []EnumTemplate
394+ // Constants are declared as const ... .... = ....
395+ Constants []ConstantTemplate
375396 // Functions are the Go function declarations
376397 Functions []FuncTemplate
377398 // Interfaces is the list of interfaces that this package implements
@@ -174,6 +174,12 @@ type RecordTemplate struct {
174 // Doc is the documentation of the alias174 // Doc is the documentation of the alias
175 Doc string175 Doc string
176 176
177+ // Constructors is the slice of functions that create the class struct
178+ Constructors []FuncTemplate
179+
180+ // Receivers is the slice of functions that have value receivers to the struct
181+ Receivers []FuncTemplate
182+
177 // Fields is the list of record fields183 // Fields is the list of record fields
178 Fields []RecordField184 Fields []RecordField
179 }185 }
@@ -196,6 +202,17 @@ type EnumTemplate struct {
196 Values []enumValues202 Values []enumValues
197 }203 }
198 204
205+type ConstantTemplate struct {
206+ // Name is the name of the constant
207+ Name string
208+ // Doc is the documentation for the constant
209+ Doc string
210+ // Type is the Go type for the constant
211+ Type string
212+ // Values are the list of values for the constant
213+ Value string
214+}
215+
199 type funcRetTemplate struct {216 type funcRetTemplate struct {
200 // Raw is the raw value for the underlying purego function217 // Raw is the raw value for the underlying purego function
201 Raw string218 Raw string
@@ -342,6 +359,8 @@ type ClassTemplate struct {
342 Receivers []FuncTemplate359 Receivers []FuncTemplate
343 // Interfaces are receiver methods that are implemented because it needs to satisfy a certain interface360 // Interfaces are receiver methods that are implemented because it needs to satisfy a certain interface
344 Interfaces []InterfaceTemplate361 Interfaces []InterfaceTemplate
362+ // Functions are the Go function declarations
363+ Functions []FuncTemplate
345 // Signals are helpers for ConnectX receivers364 // Signals are helpers for ConnectX receivers
346 Signals []SignalsTemplate365 Signals []SignalsTemplate
347 }366 }
@@ -372,6 +391,8 @@ type TemplateArg struct {
372 Callbacks []CallbackTemplate391 Callbacks []CallbackTemplate
373 // Enums are enumerations declared as const ... .... = ....392 // Enums are enumerations declared as const ... .... = ....
374 Enums []EnumTemplate393 Enums []EnumTemplate
394+ // Constants are declared as const ... .... = ....
395+ Constants []ConstantTemplate
375 // Functions are the Go function declarations396 // Functions are the Go function declarations
376 Functions []FuncTemplate397 Functions []FuncTemplate
377 // Interfaces is the list of interfaces that this package implements398 // Interfaces is the list of interfaces that this package implements
M internal/gir/types/types.go +18 -0
@@ -4,6 +4,7 @@ package types
44
55 import (
66 "encoding/xml"
7+ "fmt"
78 "strconv"
89 "strings"
910
@@ -333,6 +334,23 @@ type Constant struct {
333334 InfoElements
334335 }
335336
337+func (c *Constant) Template(ns string, kinds KindMap) ConstantTemplate {
338+ t := c.Type.Template(ns, kinds)
339+ v := c.Value
340+
341+ switch t {
342+ case "string":
343+ v = fmt.Sprintf(`"%s"`, v)
344+ }
345+
346+ return ConstantTemplate{
347+ Name: c.Name,
348+ Doc: c.Doc.StringSafe(),
349+ Type: t,
350+ Value: v,
351+ }
352+}
353+
336354 type Constructor struct {
337355 XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 constructor"`
338356 CallableAttrs
@@ -4,6 +4,7 @@ package types
4 4
5 import (5 import (
6 "encoding/xml"6 "encoding/xml"
7+ "fmt"
7 "strconv"8 "strconv"
8 "strings"9 "strings"
9 10
@@ -333,6 +334,23 @@ type Constant struct {
333 InfoElements334 InfoElements
334 }335 }
335 336
337+func (c *Constant) Template(ns string, kinds KindMap) ConstantTemplate {
338+ t := c.Type.Template(ns, kinds)
339+ v := c.Value
340+
341+ switch t {
342+ case "string":
343+ v = fmt.Sprintf(`"%s"`, v)
344+ }
345+
346+ return ConstantTemplate{
347+ Name: c.Name,
348+ Doc: c.Doc.StringSafe(),
349+ Type: t,
350+ Value: v,
351+ }
352+}
353+
336 type Constructor struct {354 type Constructor struct {
337 XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 constructor"`355 XMLName xml.Name `xml:"http://www.gtk.org/introspection/core/1.0 constructor"`
338 CallableAttrs356 CallableAttrs
M templates/go +66 -0
@@ -30,6 +30,37 @@ type {{.Name}} struct {
3030 {{.Name}} {{.Type}}
3131 {{end}}
3232 }
33+
34+func (x *{{.Name}}) GoPointer() uintptr {
35+ return uintptr(unsafe.Pointer(x))
36+}
37+
38+{{$outer := .}}
39+
40+{{range .Constructors -}}
41+var x{{.Name}}{{$outer.Name}} func({{conv .Args.Pure.Types}}) {{.Ret.Raw}}
42+
43+
44+{{.Doc}}
45+func {{.Name}}{{$outer.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
46+ {{.Ret.Preamble $NotGLib}}
47+ {{if .Ret.Value}}cret :={{end}}x{{.Name}}{{$outer.Name}}({{conv .Args.API.Call}})
48+ {{.Ret.Fmt $NotGObject}}
49+}
50+{{end}}
51+
52+{{$outer := .}}
53+{{range .Receivers -}}
54+var x{{$outer.Name}}{{.Name}} func(uintptr {{convc .Args.Pure.Types}}) {{.Ret.Raw}}
55+
56+{{.Doc}}
57+func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
58+ {{.Ret.Preamble $NotGLib}}
59+ {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convc .Args.API.Call}})
60+ {{.Ret.Fmt $NotGObject}}
61+}
62+{{end}}
63+
3364 {{end}}
3465
3566 {{range .Interfaces -}}
@@ -73,6 +104,15 @@ var {{.Namespace}}X{{.FullName}} func(uintptr {{convc .Args.Pure.Types}}) {{.Ret
73104 type {{.Name}} = {{.Value}}
74105 {{end}}
75106
107+{{if .Constants -}}
108+const (
109+{{range .Constants -}}
110+ {{.Doc}}
111+ {{.Name}} {{.Type}} = {{.Value}}
112+{{end}}
113+)
114+{{end}}
115+
76116 {{range .Enums -}}
77117 {{.Doc}}
78118 type {{.Name}} int
@@ -175,6 +215,17 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
175215 {{end}}
176216 {{end}}
177217
218+{{range .Functions -}}
219+var x{{.Name}} func({{conv .Args.Pure.Types}}) {{.Ret.Raw}}
220+
221+{{.Doc}}
222+func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
223+ {{.Ret.Preamble $NotGLib}}
224+ {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{conv .Args.API.Call}})
225+ {{.Ret.Fmt $NotGObject}}
226+}
227+{{end}}
228+
178229 {{end}}
179230
180231
@@ -188,6 +239,17 @@ func init() {
188239 {{range .Functions -}}
189240 core.PuregoSafeRegister(&x{{.Name}}, lib, "{{.CName}}")
190241 {{end}}
242+
243+ {{range .Records -}}
244+ {{$rec := .}}
245+ {{range .Constructors -}}
246+ core.PuregoSafeRegister(&x{{.Name}}{{$rec.Name}}, lib, "{{.CName}}")
247+ {{end}}
248+ {{range .Receivers -}}
249+ core.PuregoSafeRegister(&x{{$rec.Name}}{{.Name}}, lib, "{{.CName}}")
250+ {{end}}
251+ {{end}}
252+
191253 {{range .Classes -}}
192254 {{$cls := .}}
193255 {{range .Constructors -}}
@@ -196,7 +258,11 @@ func init() {
196258 {{range .Receivers -}}
197259 core.PuregoSafeRegister(&x{{$cls.Name}}{{.Name}}, lib, "{{.CName}}")
198260 {{end}}
261+ {{range .Functions -}}
262+ core.PuregoSafeRegister(&x{{.Name}}, lib, "{{.CName}}")
263+ {{end}}
199264 {{end}}
265+
200266 {{range .Interfaces -}}
201267 {{range .Methods -}}
202268 core.PuregoSafeRegister(&{{.Namespace}}X{{.FullName}}, lib, "{{.CName}}")
@@ -30,6 +30,37 @@ type {{.Name}} struct {
30 {{.Name}} {{.Type}}30 {{.Name}} {{.Type}}
31 {{end}}31 {{end}}
32 }32 }
33+
34+func (x *{{.Name}}) GoPointer() uintptr {
35+ return uintptr(unsafe.Pointer(x))
36+}
37+
38+{{$outer := .}}
39+
40+{{range .Constructors -}}
41+var x{{.Name}}{{$outer.Name}} func({{conv .Args.Pure.Types}}) {{.Ret.Raw}}
42+
43+
44+{{.Doc}}
45+func {{.Name}}{{$outer.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
46+ {{.Ret.Preamble $NotGLib}}
47+ {{if .Ret.Value}}cret :={{end}}x{{.Name}}{{$outer.Name}}({{conv .Args.API.Call}})
48+ {{.Ret.Fmt $NotGObject}}
49+}
50+{{end}}
51+
52+{{$outer := .}}
53+{{range .Receivers -}}
54+var x{{$outer.Name}}{{.Name}} func(uintptr {{convc .Args.Pure.Types}}) {{.Ret.Raw}}
55+
56+{{.Doc}}
57+func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
58+ {{.Ret.Preamble $NotGLib}}
59+ {{if .Ret.Value}}cret :={{end}}x{{$outer.Name}}{{.Name}}(x.GoPointer() {{convc .Args.API.Call}})
60+ {{.Ret.Fmt $NotGObject}}
61+}
62+{{end}}
63+
33 {{end}}64 {{end}}
34 65
35 {{range .Interfaces -}}66 {{range .Interfaces -}}
@@ -73,6 +104,15 @@ var {{.Namespace}}X{{.FullName}} func(uintptr {{convc .Args.Pure.Types}}) {{.Ret
73 type {{.Name}} = {{.Value}}104 type {{.Name}} = {{.Value}}
74 {{end}}105 {{end}}
75 106
107+{{if .Constants -}}
108+const (
109+{{range .Constants -}}
110+ {{.Doc}}
111+ {{.Name}} {{.Type}} = {{.Value}}
112+{{end}}
113+)
114+{{end}}
115+
76 {{range .Enums -}}116 {{range .Enums -}}
77 {{.Doc}}117 {{.Doc}}
78 type {{.Name}} int118 type {{.Name}} int
@@ -175,6 +215,17 @@ func (x *{{$outer.Name}}) {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
175 {{end}}215 {{end}}
176 {{end}}216 {{end}}
177 217
218+{{range .Functions -}}
219+var x{{.Name}} func({{conv .Args.Pure.Types}}) {{.Ret.Raw}}
220+
221+{{.Doc}}
222+func {{.Name}}({{conv .Args.API.Full}}) {{.Ret.Return}} {
223+ {{.Ret.Preamble $NotGLib}}
224+ {{if .Ret.Value}}cret := {{end}}x{{.Name}}({{conv .Args.API.Call}})
225+ {{.Ret.Fmt $NotGObject}}
226+}
227+{{end}}
228+
178 {{end}}229 {{end}}
179 230
180 231
@@ -188,6 +239,17 @@ func init() {
188 {{range .Functions -}}239 {{range .Functions -}}
189 core.PuregoSafeRegister(&x{{.Name}}, lib, "{{.CName}}")240 core.PuregoSafeRegister(&x{{.Name}}, lib, "{{.CName}}")
190 {{end}}241 {{end}}
242+
243+ {{range .Records -}}
244+ {{$rec := .}}
245+ {{range .Constructors -}}
246+ core.PuregoSafeRegister(&x{{.Name}}{{$rec.Name}}, lib, "{{.CName}}")
247+ {{end}}
248+ {{range .Receivers -}}
249+ core.PuregoSafeRegister(&x{{$rec.Name}}{{.Name}}, lib, "{{.CName}}")
250+ {{end}}
251+ {{end}}
252+
191 {{range .Classes -}}253 {{range .Classes -}}
192 {{$cls := .}}254 {{$cls := .}}
193 {{range .Constructors -}}255 {{range .Constructors -}}
@@ -196,7 +258,11 @@ func init() {
196 {{range .Receivers -}}258 {{range .Receivers -}}
197 core.PuregoSafeRegister(&x{{$cls.Name}}{{.Name}}, lib, "{{.CName}}")259 core.PuregoSafeRegister(&x{{$cls.Name}}{{.Name}}, lib, "{{.CName}}")
198 {{end}}260 {{end}}
261+ {{range .Functions -}}
262+ core.PuregoSafeRegister(&x{{.Name}}, lib, "{{.CName}}")
263+ {{end}}
199 {{end}}264 {{end}}
265+
200 {{range .Interfaces -}}266 {{range .Interfaces -}}
201 {{range .Methods -}}267 {{range .Methods -}}
202 core.PuregoSafeRegister(&{{.Namespace}}X{{.FullName}}, lib, "{{.CName}}")268 core.PuregoSafeRegister(&{{.Namespace}}X{{.FullName}}, lib, "{{.CName}}")
M templates/gobject +2 -32
@@ -1,11 +1,9 @@
11 package gobject
22
33 import (
4- "os"
54 "reflect"
65
76 "github.com/jwijenbergh/purego"
8- "github.com/jwijenbergh/puregotk/internal/core"
97 )
108
119 type Ptr interface {
@@ -39,11 +37,11 @@ func (o Object) Cast(v Ptr) {
3937 }
4038
4139 func (o Object) ConnectSignal(signal string, cb func()) uint32 {
42- return SignalConnect(o.GoPointer(), signal, purego.NewCallback(cb))
40+ return SignalConnect(o.GoPointer(), signal, purego.NewCallback(cb))
4341 }
4442
4543 func (o Object) DisconnectSignal(handler uint32) {
46- SignalHandlerDisconnect(&o, handler)
44+ SignalHandlerDisconnect(&o, handler)
4745 }
4846
4947 // NewCallback is an alias to purego.NewCallback
@@ -79,31 +77,3 @@ const (
7977 TypeReservedBseLastVal = 48 << 2
8078 TypeReservedUserFirstVal = 49 << 2
8179 )
82-
83-var xValueGetString func(*Value) string
84-
85-func (v *Value) String() string {
86- return xValueGetString(v)
87-}
88-
89-var xValueGetInt func(*Value) int
90-
91-func (v *Value) Int() int {
92- return xValueGetInt(v)
93-}
94-
95-var xValueUnset func(*Value)
96-
97-func (x *Value) Unset() {
98- xValueUnset(x)
99-}
100-
101-func init() {
102- lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL)
103- if err != nil {
104- panic(err)
105- }
106- core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string")
107- core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int")
108- core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset")
109-}
@@ -1,11 +1,9 @@
1 package gobject1 package gobject
2 2
3 import (3 import (
4- "os"
5 "reflect"4 "reflect"
6 5
7 "github.com/jwijenbergh/purego"6 "github.com/jwijenbergh/purego"
8- "github.com/jwijenbergh/puregotk/internal/core"
9 )7 )
10 8
11 type Ptr interface {9 type Ptr interface {
@@ -39,11 +37,11 @@ func (o Object) Cast(v Ptr) {
39 }37 }
40 38
41 func (o Object) ConnectSignal(signal string, cb func()) uint32 {39 func (o Object) ConnectSignal(signal string, cb func()) uint32 {
42- return SignalConnect(o.GoPointer(), signal, purego.NewCallback(cb))40+ return SignalConnect(o.GoPointer(), signal, purego.NewCallback(cb))
43 }41 }
44 42
45 func (o Object) DisconnectSignal(handler uint32) {43 func (o Object) DisconnectSignal(handler uint32) {
46- SignalHandlerDisconnect(&o, handler)44+ SignalHandlerDisconnect(&o, handler)
47 }45 }
48 46
49 // NewCallback is an alias to purego.NewCallback47 // NewCallback is an alias to purego.NewCallback
@@ -79,31 +77,3 @@ const (
79 TypeReservedBseLastVal = 48 << 277 TypeReservedBseLastVal = 48 << 2
80 TypeReservedUserFirstVal = 49 << 278 TypeReservedUserFirstVal = 49 << 2
81 )79 )
82-
83-var xValueGetString func(*Value) string
84-
85-func (v *Value) String() string {
86- return xValueGetString(v)
87-}
88-
89-var xValueGetInt func(*Value) int
90-
91-func (v *Value) Int() int {
92- return xValueGetInt(v)
93-}
94-
95-var xValueUnset func(*Value)
96-
97-func (x *Value) Unset() {
98- xValueUnset(x)
99-}
100-
101-func init() {
102- lib, err := purego.Dlopen(os.Getenv("PUREGOTK_GTK_PATH"), purego.RTLD_NOW|purego.RTLD_GLOBAL)
103- if err != nil {
104- panic(err)
105- }
106- core.PuregoSafeRegister(&xValueGetString, lib, "g_value_get_string")
107- core.PuregoSafeRegister(&xValueGetInt, lib, "g_value_get_int")
108- core.PuregoSafeRegister(&xValueUnset, lib, "g_value_unset")
109-}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close