From 370fb89367fd66fd83b63a29a5a2b6f949a75e15 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Thu, 30 Mar 2023 20:33:53 +0200 Subject: [PATCH] Add / rename functions for loading other sources --- src/builtins.c | 10 +++++----- src/globals.apfl | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index 5e949b8..d187506 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -499,7 +499,7 @@ impl_fclose(apfl_ctx ctx) static void loadfile(apfl_ctx ctx) { - ONE_ARG(ctx, "loadfile"); + ONE_ARG(ctx, "load-file"); apfl_copy(ctx, -1); const char *filename = getcstring(ctx, -1); @@ -519,9 +519,9 @@ loadfile(apfl_ctx ctx) static void loadstring(apfl_ctx ctx) { - ONE_ARG(ctx, "loadstring"); + ONE_ARG(ctx, "load-string"); apfl_tostring(ctx, -1); - apfl_push_const_string(ctx, "(loadstring)"); + apfl_push_const_string(ctx, "(load-string)"); struct apfl_io_string_reader_data reader_data = apfl_io_string_reader_create(apfl_get_string(ctx, -2)); struct apfl_io_reader r = apfl_io_string_reader(&reader_data); @@ -715,8 +715,8 @@ apfl_builtins(apfl_ctx ctx) add_builtin(ctx, "fread", impl_fread); add_builtin(ctx, "fwrite", impl_fwrite); add_builtin(ctx, "fclose", impl_fclose); - add_builtin(ctx, "loadfile", loadfile); - add_builtin(ctx, "loadstring", loadstring); + add_builtin(ctx, "load-file", loadfile); + add_builtin(ctx, "load-string", loadstring); add_builtin(ctx, "-serialize-bytecode", serialize_bytecode); add_builtin(ctx, "-unserialize-bytecode", unserialize_bytecode); add_builtin(ctx, "set-func-name", set_func_name); diff --git a/src/globals.apfl b/src/globals.apfl index 8130192..bc63a43 100644 --- a/src/globals.apfl +++ b/src/globals.apfl @@ -24,8 +24,8 @@ fread := builtins.fread fwrite := builtins.fwrite fclose := builtins.fclose - loadfile := builtins.loadfile - loadstring := builtins.loadstring + load-file := builtins.load-file + load-string := builtins.load-string get-optional := builtins.get-optional raise := builtins.raise symbol := builtins.symbol @@ -195,6 +195,10 @@ } (get-optional k container) } + run-file := { f -> + ((load-file f)) + } + # Dictionary of exported functions [ 'if -> if @@ -224,8 +228,9 @@ 'fread -> fread 'fwrite -> fwrite 'fclose -> fclose - 'loadfile -> loadfile - 'loadstring -> loadstring + 'load-file -> load-file + 'load-string -> load-string + 'run-file -> run-file '-serialize-bytecode -> -serialize-bytecode '-unserialize-bytecode -> -unserialize-bytecode '& -> &