reorganize: consolidate demo directories
- 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>
This commit is contained in:
63
_demo/c/genints/genints.go
Normal file
63
_demo/c/genints/genints.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
type generator struct {
|
||||
val c.Int
|
||||
}
|
||||
|
||||
func (g *generator) next() c.Int {
|
||||
g.val++
|
||||
return g.val
|
||||
}
|
||||
|
||||
func genInts(n int, gen func() c.Int) []c.Int {
|
||||
a := make([]c.Int, n)
|
||||
for i := range a {
|
||||
a[i] = gen()
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func main() {
|
||||
// generate 5 random integers
|
||||
for _, v := range genInts(5, c.Rand) {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
|
||||
// generate 5 integers, each is double of the previous one
|
||||
initVal := c.Int(1)
|
||||
ints := genInts(5, func() c.Int {
|
||||
initVal *= 2
|
||||
return initVal
|
||||
})
|
||||
for _, v := range ints {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
|
||||
// generate 5 integers, each is incremented by 1
|
||||
g := &generator{val: 1}
|
||||
for _, v := range genInts(5, g.next) {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
}
|
||||
|
||||
/* Posible output:
|
||||
16807
|
||||
282475249
|
||||
1622650073
|
||||
984943658
|
||||
1144108930
|
||||
2
|
||||
4
|
||||
8
|
||||
16
|
||||
32
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
*/
|
||||
Reference in New Issue
Block a user