12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #!/usr/bin/env ruby
- TEMPLATE=<<EOT
- type XXX struct {
- handle * C.YYY
- }
- // Converts a zzz to it's underlying C pointer
- func (self * XXX) toC() *C.YYY {
- return (*C.YYY)(self.handle)
- }
- // Destroys the zzz.
- func (self *XXX) Destroy() {
- if self.handle != nil {
- C.al_destroy_zzz(self.toC())
- }
- self.handle = nil
- }
- // Wraps a C zzz into a go zzz
- func wrapXXXRaw(data *C.YYY) *XXX {
- if data == nil {
- return nil
- }
- return &XXX{data}
- }
- // Sets up a finalizer for this XXX that calls Destroy()
- func (self *XXX) SetDestroyFinalizer() *XXX {
- if self != nil {
- runtime.SetFinalizer(self, func(me *XXX) { me.Destroy() })
- }
- return self
- }
- // Wraps a C zzz into a go zzz and sets up a finalizer that calls Destroy()
- func wrapXXX(data *C.YYY) *XXX {
- self := wrapXXXRaw(data)
- return self.SetDestroyFinalizer()
- }
- EOT
- gotype = ARGV[0] || 'XXX'
- ctype = ARGV[1] || 'YYY'
- funcname = ARGV[2] || 'zzz'
- res = TEMPLATE.gsub('XXX', gotype).gsub('YYY',ctype).gsub('zzz', funcname)
- puts res
-
|