cl: c.Func (llgo.funcAddr); demo: cppintf (how to use c++ interface)

This commit is contained in:
xushiwei
2024-06-21 23:44:56 +08:00
parent be0ce57375
commit bfa4e08a4e
11 changed files with 149 additions and 35 deletions

37
_demo/cppintf/cppintf.go Normal file
View File

@@ -0,0 +1,37 @@
package main
import (
"github.com/goplus/llgo/_demo/cppintf/foo"
"github.com/goplus/llgo/c"
)
type Bar struct {
foo.Callback
a int
b float64
}
func NewBar(a int, b float64) *Bar {
return &Bar{
Callback: foo.Callback{
Vptr: &foo.CallbackVtbl{
ValA: c.Func((*Bar).getA),
ValB: c.Func((*Bar).getB),
},
},
a: a, b: b,
}
}
func (p *Bar) getA() int {
return p.a
}
func (p *Bar) getB() float64 {
return p.b
}
func main() {
bar := NewBar(1, 2.0)
foo.F(&bar.Callback)
}