mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 05:14:45 +00:00
add standard I/O streams and few functions
This commit is contained in:
parent
9e0550736a
commit
7fd0005735
@ -75,6 +75,14 @@ class Core implements ILib
|
||||
));
|
||||
}
|
||||
|
||||
$env->set('php-sapi', new CoreFunc('php-sapi', 'Get the name of the PHP SAPI.', 0, 0,
|
||||
fn () => php_sapi_name()
|
||||
));
|
||||
|
||||
$env->set('php-version', new CoreFunc('php-version', 'Get the PHP version.', 0, 0,
|
||||
fn () => phpversion()
|
||||
));
|
||||
|
||||
if (!$this->safemode) {
|
||||
$env->set('print', new CoreFunc('print', 'Print arguments.', 0, -1,
|
||||
function (...$args) {
|
||||
|
@ -18,6 +18,13 @@ class IO implements ILib
|
||||
$env->set('DIRSEP', \DIRECTORY_SEPARATOR);
|
||||
$env->set('HOME', $_SERVER['HOME'] . \DIRECTORY_SEPARATOR);
|
||||
|
||||
if (php_sapi_name() == 'cli') {
|
||||
// Define standard I/O streams
|
||||
$env->set('STDIN', STDIN);
|
||||
$env->set('STDOUT', STDOUT);
|
||||
$env->set('STDERR', STDERR);
|
||||
}
|
||||
|
||||
$env->set('wd', new CoreFunc('wd', 'Get the current working directory.', 0, 0,
|
||||
fn () => getcwd() . \DIRECTORY_SEPARATOR
|
||||
));
|
||||
@ -34,6 +41,10 @@ class IO implements ILib
|
||||
fn (string $dir) => is_dir($dir)
|
||||
));
|
||||
|
||||
$env->set('tty?', new CoreFunc('tty?', 'Return true if the given file descriptor is a TTY.', 1, 1,
|
||||
fn ($stream) => stream_isatty($stream)
|
||||
));
|
||||
|
||||
$env->set('fsize', new CoreFunc('fsize', 'Return the size of a file.', 1, 1,
|
||||
fn (string $file) => @filesize($file)
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user