Skip to content

Commit 4a0d2b1

Browse files
committedMay 30, 2023
Fix header registry.
1 parent 9e9544f commit 4a0d2b1

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed
 

‎libs/reglibs.go

+18-26
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,30 @@ import (
77
"strings"
88
)
99

10-
//go:embed includes/embed/*
10+
//go:embed includes/embed
1111
var efs embed.FS
1212

1313
func init() {
14-
15-
onFile := func(path string, d fs.DirEntry, err error) error {
16-
if d.IsDir() {
14+
const root = "includes/embed"
15+
err := fs.WalkDir(efs, root, func(path string, d fs.DirEntry, err error) error {
16+
if err != nil {
17+
return err
18+
} else if d.IsDir() {
1719
return nil
1820
}
19-
return registerInclude(path)
20-
}
21-
22-
err := fs.WalkDir(efs, ".", onFile)
23-
21+
data, err := efs.ReadFile(path)
22+
if err != nil {
23+
return err
24+
}
25+
fname := strings.TrimPrefix(path, root+"/")
26+
RegisterLibrary(fname, func(env *Env) *Library {
27+
return &Library{
28+
Header: fmt.Sprintf("#include <%s>\n%s", BuiltinH, string(data)),
29+
}
30+
})
31+
return nil
32+
})
2433
if err != nil {
2534
panic(err)
2635
}
2736
}
28-
29-
func registerInclude(fName string) error {
30-
31-
fBuff, fErr := efs.ReadFile(fName)
32-
33-
if fErr != nil {
34-
return fErr
35-
}
36-
37-
RegisterLibrary(strings.TrimPrefix(fName, "includes/"), func(env *Env) *Library {
38-
return &Library{
39-
Header: fmt.Sprintf("#include <%s>\n%s", BuiltinH, string(fBuff)),
40-
}
41-
})
42-
43-
return nil
44-
}

‎libs/reglibs_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package libs
22

33
import (
4-
"github.com/gotranspile/cxgo/types"
5-
"github.com/stretchr/testify/require"
64
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/gotranspile/cxgo/types"
79
)
810

911
var autoRegLibs = []string{
10-
1112
"AL/alc.h",
1213
"AL/al.h",
13-
14+
1415
"dirent.h",
1516
"fcntl.h",
1617
"float.h",
1718
"getopt.h",
18-
19+
1920
"GL/gl.h",
20-
21+
2122
"inttypes.h",
2223
"libgen.h",
2324
"sched.h",
2425
"semaphore.h",
2526
"signal.h",
2627
"strings.h",
27-
28+
2829
"sys/mkdev.h",
2930
"windows.h",
3031
}

0 commit comments

Comments
 (0)