Add / rename functions for loading other sources

This commit is contained in:
Laria 2023-03-30 20:33:53 +02:00
parent 0e9f8ae0ee
commit 370fb89367
2 changed files with 14 additions and 9 deletions

View file

@ -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);

View file

@ -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
'& -> &