diff --git a/src/env.c b/src/env.c index 75f7351..abbe817 100644 --- a/src/env.c +++ b/src/env.c @@ -204,6 +204,7 @@ struct Environment defaultEnv() {"prn", &print}, {"pch", &pChar}, {"penv", &printEnvO}, {"eval", &parseEvalO}, #ifdef STANDALONE + {"loadfile", &loadFile}, {"inp", &takeInput}, #endif }; diff --git a/src/pebblisp.c b/src/pebblisp.c index a18f1ff..920dafe 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -771,9 +771,20 @@ int readFile(const char *filename, struct Environment *env) { return 0; } +Object loadFile(Object filename, Object _, struct Environment *env) { + if (isStringy(filename)) { + readFile(filename.string, env); + return numberObject(0); + } + return numberObject(1); +} + void repl(struct Environment *env) { - readFile(SCRIPTDIR "/repl.pbl", env); + if (readFile(SCRIPTDIR "/repl.pbl", env) == 1) { + fprintf(stderr, "Could not read '%s'\n", SCRIPTDIR "/repl.pbl"); + fprintf(stderr, "Consider installing or reinstalling pebblisp.\n"); + } } int main(int argc, const char* argv[]) diff --git a/src/pebblisp.h b/src/pebblisp.h index 8a9bdc0..f188bf1 100644 --- a/src/pebblisp.h +++ b/src/pebblisp.h @@ -66,6 +66,7 @@ Object parseEvalO(Object text, Object ignore, struct Environment *env); #ifdef STANDALONE Object takeInput(Object i1, Object i2, struct Environment *i3); +Object loadFile(Object filename, Object _, struct Environment *env); #endif #endif diff --git a/src/tests.sh b/src/tests.sh index b763eb5..a800dff 100755 --- a/src/tests.sh +++ b/src/tests.sh @@ -42,9 +42,9 @@ fail() { check() { local output if (($VALGRIND == 1)); then - local output=$($VALCOM ./pl "$2") + local output=$($VALCOM ./pl "(loadfile \"examples/lib.pbl\") $2") else - local output=$(./pl "$2") + local output=$(./pl "(loadfile \"examples/lib.pbl\") $2") fi if [ "$output" == "$3" ]; then