Implement loadfile in lib.pbl
This commit is contained in:
parent
a2b0e0813b
commit
9abec12d99
|
@ -209,7 +209,6 @@ struct Environment defaultEnv()
|
|||
pf(numToChar),
|
||||
pf(printEnvO),
|
||||
pf(systemCall),
|
||||
pf(loadFile),
|
||||
pf(cd),
|
||||
pf(cwd),
|
||||
pf(takeInput),
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
(prn (cat _txt (ch 10)))
|
||||
)))
|
||||
|
||||
(def loadfile (fn (file-name) (
|
||||
(eval (rf file-name))
|
||||
)))
|
||||
|
||||
; Exponentiate a^b
|
||||
(def exp (fn (a b)
|
||||
(if (= b 0)
|
||||
|
|
12
src/plfunc.c
12
src/plfunc.c
|
@ -483,18 +483,6 @@ Object takeInput(Object* params, int length, unused struct Environment* env)
|
|||
return errorWithContext(NULL_PARSE, "fgets() error");
|
||||
}
|
||||
|
||||
Object loadFile(Object* params, unused int length, struct Environment* env)
|
||||
{
|
||||
checkTypes(loadFile)
|
||||
Object filename = params[0];
|
||||
|
||||
if (isStringy(filename)) {
|
||||
readFile(filename.string, env);
|
||||
return numberObject(0);
|
||||
}
|
||||
return numberObject(1);
|
||||
}
|
||||
|
||||
Object cd(Object* params, unused int length, unused struct Environment* env)
|
||||
{
|
||||
checkTypes(cd)
|
||||
|
|
|
@ -261,15 +261,6 @@ tfn(systemCall, "sys",
|
|||
"(sys \"echo yee > /dev/null\")", "0",
|
||||
);
|
||||
|
||||
tfn(loadFile, "loadfile",
|
||||
({ expect(isStringy), anyType }),
|
||||
"Loads and parses the given file.\n"
|
||||
"Returns 0 if the file was loaded and parsed successfully. Otherwise 1.\n"
|
||||
"(loadfile \"printdate.pl\")\n"
|
||||
"Mon 21 Mar 2022 10:35:03 AM EDT\n"
|
||||
"=> 0"
|
||||
);
|
||||
|
||||
tfn(cd, "cd",
|
||||
({ expect(isStringy), anyType }),
|
||||
"Change the current directory."
|
||||
|
|
Loading…
Reference in New Issue