Skip to content

Commit 9dd3401

Browse files
committed
Support GLJ classpath load paths
1 parent 422f830 commit 9dd3401

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

pkg/gljmain/gljmain.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99
"os"
1010
"os/signal"
11+
"path/filepath"
1112
"strconv"
1213
"strings"
1314
"syscall"
@@ -54,7 +55,11 @@ For more information, visit: https://github.com/glojurelang/glojure
5455
}
5556

5657
func Main(args []string) {
57-
runtime.AddLoadPath(os.DirFS("."))
58+
for _, path := range filepath.SplitList(os.Getenv("GLJ_CLASSPATH")) {
59+
if path != "" {
60+
runtime.AddLoadPath(os.DirFS(path))
61+
}
62+
}
5863

5964
if len(args) == 0 {
6065
// Check if stdin is a terminal

pkg/runtime/envinit.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ func NewEnvironment(opts ...EvalOption) lang.Environment {
189189
return nil
190190
}), true)
191191

192+
lang.InternVar(core, lang.NewSymbol("load"), lang.FnFunc(func(paths ...any) any {
193+
if len(paths) == 0 {
194+
panic("Wrong number of args passed to: clojure.core/load")
195+
}
196+
for _, path := range paths {
197+
RT.Load(path.(string))
198+
}
199+
return nil
200+
}), true)
201+
192202
lang.InternVar(core, lang.NewSymbol("load-file"), lang.FnFunc1(func(filename any) any {
193203
fname := filename.(string)
194204
buf, err := os.ReadFile(fname)

pkg/runtime/rtcompat.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,11 @@ func (rt *RTMethods) Load(scriptBase string) {
188188
PushThreadBindings(NewMap(kvs...))
189189
defer PopThreadBindings()
190190

191+
resourceBase := strings.ReplaceAll(strings.TrimPrefix(scriptBase, "/"), ".", "/")
192+
191193
if useAot {
192194
// check nsloaders
193-
if loader := GetNSLoader(strings.TrimPrefix(scriptBase, "/")); loader != nil {
195+
if loader := GetNSLoader(resourceBase); loader != nil {
194196
loader()
195197
return
196198
}
@@ -205,10 +207,9 @@ func (rt *RTMethods) Load(scriptBase string) {
205207
loadPathLock.Unlock()
206208
for _, fs := range lp {
207209
for _, testFilename := range []string{
208-
scriptBase,
209-
scriptBase + ".glj",
210-
scriptBase + ".clj",
211-
scriptBase + ".cljc",
210+
resourceBase + ".glj",
211+
resourceBase + ".clj",
212+
resourceBase + ".cljc",
212213
} {
213214
b, err := readFile(fs, testFilename)
214215
if err == nil {

0 commit comments

Comments
 (0)