mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-30 23:23:07 +00:00 
			
		
		
		
	Make native modules easier to import.
This commit is contained in:
		| @@ -19,7 +19,7 @@ | |||||||
| # IN THE SOFTWARE. | # IN THE SOFTWARE. | ||||||
|  |  | ||||||
| CFLAGS=-std=c99 -Wall -Wextra -I../../src/include -O2 -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -shared -fpic | CFLAGS=-std=c99 -Wall -Wextra -I../../src/include -O2 -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -shared -fpic | ||||||
| TARGET=libdstsqlite3.so | TARGET=sqlite3.so | ||||||
|  |  | ||||||
| sqlite-autoconf-3230100/sqlite3.%: | sqlite-autoconf-3230100/sqlite3.%: | ||||||
| 	curl https://www.sqlite.org/2018/sqlite-autoconf-3230100.tar.gz | tar -xvz | 	curl https://www.sqlite.org/2018/sqlite-autoconf-3230100.tar.gz | tar -xvz | ||||||
|   | |||||||
| @@ -984,29 +984,37 @@ environment is needed, use run-context." | |||||||
|  |  | ||||||
| (def module.native-paths @[ | (def module.native-paths @[ | ||||||
|   "./?.so" |   "./?.so" | ||||||
|  |   "./?/??.so" | ||||||
|   "./dst_modules/?.so" |   "./dst_modules/?.so" | ||||||
|  |   "./dst_modules/?/??.so" | ||||||
|   "/usr/local/dst/0.0.0/?.so" |   "/usr/local/dst/0.0.0/?.so" | ||||||
|  |   "/usr/local/dst/0.0.0/?/??.so" | ||||||
|  ]) |  ]) | ||||||
|  |  | ||||||
|  | (defn module.find | ||||||
|  |   [path paths] | ||||||
|  |   (def parts (string.split "." path)) | ||||||
|  |   (def last (get parts (- (length parts) 1))) | ||||||
|  |   (def normname (string.replace-all "." "/" path)) | ||||||
|  |   (array.push | ||||||
|  |     (map (fn [x]  | ||||||
|  |              (def y (string.replace "??" last x)) | ||||||
|  |              (string.replace "?" normname y)) | ||||||
|  |          paths) | ||||||
|  |     path)) | ||||||
|  |  | ||||||
| (def require | (def require | ||||||
|  "Require a module with the given name. Will search all of the paths in |  "Require a module with the given name. Will search all of the paths in | ||||||
| module.paths, then the path as a raw file path. Returns the new environment | module.paths, then the path as a raw file path. Returns the new environment | ||||||
| returned from compiling and running the file." | returned from compiling and running the file." | ||||||
|  (do |  (do | ||||||
|  |  | ||||||
|    (defn transform |  | ||||||
|     [path paths] |  | ||||||
|     (def normname (string.replace-all "." "/" path)) |  | ||||||
|     (array.push |  | ||||||
|       (map (fn [x] (string.replace "?" normname x)) paths) |  | ||||||
|       path)) |  | ||||||
|  |  | ||||||
|   (defn check-mod |   (defn check-mod | ||||||
|     [f testpath] |     [f testpath] | ||||||
|     (if f f (file.open testpath))) |     (if f f (file.open testpath))) | ||||||
|  |  | ||||||
|   (defn find-mod [path] |   (defn find-mod [path] | ||||||
|     (def paths (transform path module.paths)) |     (def paths (module.find path module.paths)) | ||||||
|     (reduce check-mod nil paths)) |     (reduce check-mod nil paths)) | ||||||
|  |  | ||||||
|   (defn check-native |   (defn check-native | ||||||
| @@ -1016,7 +1024,7 @@ returned from compiling and running the file." | |||||||
|       (if f (do (file.close f) testpath))))) |       (if f (do (file.close f) testpath))))) | ||||||
|  |  | ||||||
|   (defn find-native [path] |   (defn find-native [path] | ||||||
|     (def paths (transform path module.native-paths)) |     (def paths (module.find path module.native-paths)) | ||||||
|     (reduce check-native nil paths)) |     (reduce check-native nil paths)) | ||||||
|  |  | ||||||
|   (def cache @{}) |   (def cache @{}) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose