This commit is contained in:
Valk Richard Li
2020-03-28 17:02:29 +08:00
committed by GitHub
parent 8dc04bf95d
commit c0f58cc2b1
7 changed files with 396 additions and 97 deletions
+9 -18
View File
@@ -11,14 +11,12 @@ var io=
# Failures are thrown as runtime errors as per die().
open:func(filename,mode="r")
{
var call_c_fopen=func(__file,__mode){};
return call_c_fopen(filename,mode);
return nasal_call_inline_c_fopen(filename,mode);
},
# Closes the specified file as per ANSI fclose().
close:func(filehandle)
{
var call_c_fclose=func(__filehandle){};
call_c_fclose(filehandle);
nasal_call_inline_c_fclose(filehandle);
return;
},
# Attempts to read length bytes from the filehandle into the beginning of the mutable string buf.
@@ -26,16 +24,14 @@ var io=
# Returns the number of bytes successfully read.
read:func(filehandle,buf,length)
{
var call_c_read=func(__filehandle,__buf,__len){};
return call_c_read(filehandle,buf,length);
return nasal_call_inline_c_read(filehandle,buf,length);
},
# Attempts to write the entirety of the specified string to the filehandle.
# Failures are thrown as runtime errors as per die().
# Returns the number of bytes successfully written.
write:func(filehandle,str)
{
var call_c_write=func(__filehandle,__str){};
return call_c_write(filehandle,str);
return nasal_call_inline_c_write(filehandle,str);
},
# As ANSI fseek().
# Attempts to seek to the specified position based on the whence value
@@ -45,15 +41,13 @@ var io=
SEEK_END:3,
seek:func(filehandle,position,whence)
{
var call_c_seek=func(__filehandle,__position,__whence){};
call_c_seek(filehandle,position,whence);
nasal_call_inline_c_seek(filehandle,position,whence);
return;
},
# Returns the current seek position of the filehandle.
tell:func(filehandle)
{
var call_c_tell=func(__filehandle){};
return call_c_tell(filehandle);
return nasal_call_inline_c_tell(filehandle);
},
# Reads and returns a single text line from the filehandle.
# Interprets both "\n" and "\r\n" as end of line markers,
@@ -61,8 +55,7 @@ var io=
# End offile or error is signaled by returning nil.
readln:func(filehandle)
{
var call_builtin_c_getline=func(__filehandle){};
return call_builtin_c_getline(filehandle);
return nasal_call_inline_builtin_c_getline(filehandle);
},
# Calls unix or win32 stat() on the specified file name and
# returns a seven element array whose contents are,
@@ -70,15 +63,13 @@ var io=
# Errors are signaled as exceptions as per die().
stat:func(filename)
{
var call_builtin_stat=func(__filename){};
return call_builtin_stat(filename);
return nasal_call_inline_builtin_stat(filename);
},
};
var print=func(dyn...)
{
var __system_call_c_std_puts=func(__str){};
forindex(var i;dyn)
__system_call_c_std_puts(dyn[i]);
nasal_call_inline_c_std_puts(dyn[i]);
return nil;
};