Skip to content

Commit

Permalink
Fix header registry.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed May 30, 2023
1 parent 9e9544f commit 4a0d2b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
44 changes: 18 additions & 26 deletions libs/reglibs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,30 @@ import (
"strings"
)

//go:embed includes/embed/*
//go:embed includes/embed
var efs embed.FS

func init() {

onFile := func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
const root = "includes/embed"
err := fs.WalkDir(efs, root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
} else if d.IsDir() {
return nil
}
return registerInclude(path)
}

err := fs.WalkDir(efs, ".", onFile)

data, err := efs.ReadFile(path)
if err != nil {
return err
}
fname := strings.TrimPrefix(path, root+"/")
RegisterLibrary(fname, func(env *Env) *Library {
return &Library{
Header: fmt.Sprintf("#include <%s>\n%s", BuiltinH, string(data)),
}
})
return nil
})
if err != nil {
panic(err)
}
}

func registerInclude(fName string) error {

fBuff, fErr := efs.ReadFile(fName)

if fErr != nil {
return fErr
}

RegisterLibrary(strings.TrimPrefix(fName, "includes/"), func(env *Env) *Library {
return &Library{
Header: fmt.Sprintf("#include <%s>\n%s", BuiltinH, string(fBuff)),
}
})

return nil
}
15 changes: 8 additions & 7 deletions libs/reglibs_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package libs

import (
"github.com/gotranspile/cxgo/types"
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"

"github.com/gotranspile/cxgo/types"
)

var autoRegLibs = []string{

"AL/alc.h",
"AL/al.h",

"dirent.h",
"fcntl.h",
"float.h",
"getopt.h",

"GL/gl.h",

"inttypes.h",
"libgen.h",
"sched.h",
"semaphore.h",
"signal.h",
"strings.h",

"sys/mkdev.h",
"windows.h",
}
Expand Down

0 comments on commit 4a0d2b1

Please sign in to comment.