From 601ad7249add73d392b21c572921e0bbf6114e9f Mon Sep 17 00:00:00 2001 From: Mistivia Date: Thu, 24 Jul 2025 17:12:42 +0800 Subject: load path --- Makefile | 2 +- interp.c | 11 +++++++++-- primitives.c | 13 ++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a1a4a4c..8395b48 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ obj = $(src:.c=.o) tests=$(shell ls tests/*.c) tests_bin=$(tests:.c=.bin) -all: bamboo-lisp +all: bamboo-lisp ext_example/vector.so $(tests_bin) install: bamboo-lisp libbamboo-lisp.a sudo cp bamboo-lisp /usr/local/bin/bamboo-lisp diff --git a/interp.c b/interp.c index 4adcda2..75742f8 100644 --- a/interp.c +++ b/interp.c @@ -303,8 +303,15 @@ SExpRef Interp_load_file(Interp *interp, const char *filename) { FILE *fp = NULL; fp = fopen(filename, "r"); if (fp == NULL) { - return new_error(interp, "Failed to open file: %s\n", filename); - goto end; + str_builder_t sb; + init_str_builder(&sb); + str_builder_append(&sb, "/usr/local/share/bamboo-lisp/libs/%s", filename); + fp = fopen(sb.buf, "r"); + free(sb.buf); + if (fp == NULL) { + return new_error(interp, "Failed to open file: %s\n", filename); + goto end; + } } Parser_set_file(interp->parser, fp); SExpRef sexp, ret; diff --git a/primitives.c b/primitives.c index 1b49bfe..5efcc36 100644 --- a/primitives.c +++ b/primitives.c @@ -1,10 +1,12 @@ #include "primitives.h" + +#include +#include + #include "interp.h" #include "sexp.h" #include "parser.h" -#include - SExpRef primitive_assert_exception(Interp *interp, SExpRef args, bool istail) { SExpRef eargs = lisp_eval_args(interp, args); if (VALTYPE(eargs) == kExceptionSignal) return interp->t; @@ -83,7 +85,12 @@ SExpRef primitive_loadext(Interp *interp, SExpRef args, bool istail) { const char *filename = REF(CAR(args))->str; void *handle = dlopen(filename, RTLD_LAZY); if (!handle) { - return new_error(interp, "Failed to load library: %s\n", dlerror()); + str_builder_t sb; + init_str_builder(&sb); + str_builder_append(&sb, "/usr/local/share/bamboo-lisp/exts/%s", filename); + handle = dlopen(sb.buf, RTLD_LAZY); + free(sb.buf); + if (!handle) return new_error(interp, "Failed to load library: %s\n", filename); } dlerror(); BambooLispExtInitFn init_func = (BambooLispExtInitFn)dlsym(handle, "bamboo_lisp_ext_init"); -- cgit v1.0