- Consolidate _demo, _pydemo, _embdemo into single _demo directory structure
- Organize demos by language: _demo/{go,py,c,embed}/
- Categorize demos based on imports:
- Python library demos (py imports) → _demo/py/
- C/C++ library demos (c/cpp imports) → _demo/c/
- Go-specific demos → _demo/go/
- Embedded demos → _demo/embed/
- Move C-related demos (asm*, cabi*, cgo*, linkname, targetsbuild) from go/ to c/
- Update all path references in README.md and GitHub workflows
- Improve demo organization and navigation as requested in #1256
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
770 B
Go
51 lines
770 B
Go
package main
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/goplus/lib/c"
|
|
"github.com/goplus/lib/c/math"
|
|
"github.com/goplus/llgo/_demo/c/cppmintf/foo"
|
|
)
|
|
|
|
type Bar struct {
|
|
foo.Callback
|
|
a c.Int
|
|
}
|
|
|
|
func NewBar(a c.Int) *Bar {
|
|
return &Bar{
|
|
Callback: foo.Callback{
|
|
ICalc: foo.ICalc{
|
|
Vptr: &foo.ICalcVtbl{
|
|
Calc: c.Func((*Bar).sqrt),
|
|
},
|
|
},
|
|
IVal: foo.IVal{
|
|
Vptr: &foo.IValVtbl{
|
|
Val: c.Func(bar_IVal_getA),
|
|
},
|
|
},
|
|
},
|
|
a: a,
|
|
}
|
|
}
|
|
|
|
func (p *Bar) getA() c.Int {
|
|
return p.a
|
|
}
|
|
|
|
func bar_IVal_getA(this c.Pointer) c.Int {
|
|
const delta = -int(unsafe.Offsetof(foo.Callback{}.IVal))
|
|
return (*Bar)(c.Advance(this, delta)).getA()
|
|
}
|
|
|
|
func (p *Bar) sqrt(v float64) float64 {
|
|
return math.Sqrt(v)
|
|
}
|
|
|
|
func main() {
|
|
bar := NewBar(1)
|
|
foo.F(&bar.Callback)
|
|
}
|