Skip to content

Commit

Permalink
Add the containing directory of the includer of a file in load-path
Browse files Browse the repository at this point in the history
This solves the issue #694 reported by @Retropikzel

In file bar/baz.sld
   (define-module (bar baz)
      (export hello)
      (include "baz.scm"))

In file bar/baz.scm
    (define (hello)
       (display "Hello\n"))

We can now launch "stklos bar/baz" and the "bar" directory will be prepended
before the load-path when including "baz.scm" (before "baz.scm" was not
found).
  • Loading branch information
egallesio committed Oct 13, 2024
1 parent 0ac5a00 commit adce01f
Show file tree
Hide file tree
Showing 2 changed files with 1,982 additions and 1,960 deletions.
11 changes: 7 additions & 4 deletions lib/load.stk
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,13 @@ doc>
(let ((inc (string->symbol (format "%%~a" kind))))
(if (null? files)
(error kind "at least one parameter must be provided")
`(,inc ,@(map (lambda (x)
;; return x if find-path is null to improve messages
(or (find-path x) x))
files)))))
(let* ((src-file (current-loading-file))
(dir (and src-file (dirname src-file)))
(paths (if dir (cons dir *load-path*) *load-path*)))
`(,inc ,@(map (lambda (x)
;; return x if find-path is null to improve messages
(or (find-path x paths) x))
files))))))

(define-macro (include . files)
`(%do-include include ,files))
Expand Down
Loading

0 comments on commit adce01f

Please sign in to comment.