mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 02:59:54 +00:00
Add stdi and stdout to file io.
This commit is contained in:
parent
88138a16b3
commit
78cdf4b184
@ -38,6 +38,7 @@ int debug_compile_and_run(Gst *vm, GstValue ast, GstValue env) {
|
||||
/* Try to compile generated AST */
|
||||
gst_compiler(&c, vm);
|
||||
gst_compiler_usemodule(&c, "std");
|
||||
gst_compiler_usemodule(&c, "std.io");
|
||||
gst_compiler_globals(&c, env);
|
||||
func = gst_wrap_function(gst_compiler_compile(&c, ast));
|
||||
/* Check for compilation errors */
|
||||
|
@ -28,6 +28,5 @@
|
||||
void gst_cache_remove_string(Gst *vm, char *strmem);
|
||||
void gst_cache_remove_tuple(Gst *vm, char *tuplemem);
|
||||
void gst_cache_remove_struct(Gst *vm, char *structmem);
|
||||
void gst_cache_remove_userdata(Gst *vm, char *usermem);
|
||||
|
||||
#endif /* end of include guard: CACHE_H_LVYZMBLR */
|
||||
|
25
core/stl.c
25
core/stl.c
@ -601,6 +601,30 @@ int gst_stl_close(Gst *vm) {
|
||||
gst_c_return(vm, gst_wrap_nil());
|
||||
}
|
||||
|
||||
/* Functions in the io module */
|
||||
static const GstModuleItem const io_dat[] = {
|
||||
{"open", gst_stl_open},
|
||||
{"slurp", gst_stl_slurp},
|
||||
{"read", gst_stl_read},
|
||||
{"write", gst_stl_write},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* Load the io module */
|
||||
void gst_stlio_load(Gst *vm) {
|
||||
/* Load the normal c functions */
|
||||
GstValue module = gst_cmodule_table(vm, io_dat);
|
||||
GstTable *tab = module.data.table;
|
||||
/* Wrap stdin and stdout */
|
||||
FILE **inp = gst_userdata(vm, sizeof(FILE *), &gst_stl_filetype);
|
||||
FILE **outp = gst_userdata(vm, sizeof(FILE *), &gst_stl_filetype);
|
||||
*inp = stdin;
|
||||
*outp = stdout;
|
||||
gst_table_put(vm, tab, gst_string_cv(vm, "stdin"), gst_wrap_userdata(inp));
|
||||
gst_table_put(vm, tab, gst_string_cv(vm, "stdout"), gst_wrap_userdata(outp));
|
||||
gst_module_put(vm, "std.io", module);
|
||||
}
|
||||
|
||||
/****/
|
||||
/* Temporary */
|
||||
/****/
|
||||
@ -674,5 +698,6 @@ static const GstModuleItem const std_module[] = {
|
||||
|
||||
/* Load all libraries */
|
||||
void gst_stl_load(Gst *vm) {
|
||||
gst_stlio_load(vm);
|
||||
gst_module_put(vm, "std", gst_cmodule_struct(vm, std_module));
|
||||
}
|
||||
|
8
libs/parse.gst
Normal file
8
libs/parse.gst
Normal file
@ -0,0 +1,8 @@
|
||||
# Make parser
|
||||
|
||||
(: parser (fn [in] {
|
||||
'in in
|
||||
'line 0
|
||||
'index 0
|
||||
'states []
|
||||
}))
|
Loading…
Reference in New Issue
Block a user