mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 13:24:46 +00:00
add some directory functions and constants
This commit is contained in:
parent
85ccdcdbf1
commit
90a9b3aa53
@ -197,6 +197,8 @@ Name | Example | Example result | Description
|
||||
|
||||
Name | Example | Example result | Description
|
||||
------- | ------- | -------------- | -----------
|
||||
wd | `(wd)` | `"/home/pekka/code/madlisp/"` | Get the current working directory.
|
||||
chdir | `(chdir "/tmp")` | `true` | Change the current working directory.
|
||||
file? | `(file? "test.txt")` | `true` | Return true if the file exists.
|
||||
fread | `(fread "test.txt")` | `"content"` | Read the contents of a file.
|
||||
fwrite | `(fwrite "test.txt" "content")` | `true` | Write string to file. Give optional third parameter as `true` to append.
|
||||
@ -284,8 +286,10 @@ The following constants are defined by default:
|
||||
|
||||
Name | PHP constant
|
||||
------- | ------------
|
||||
pi | M_PI
|
||||
dirsep | DIRECTORY_SEPARATOR
|
||||
homedir | $_SERVER['HOME']
|
||||
ln | PHP_EOL
|
||||
pi | M_PI
|
||||
|
||||
## Extending
|
||||
|
||||
|
@ -8,6 +8,17 @@ class IO implements ILib
|
||||
{
|
||||
public function register(Env $env): void
|
||||
{
|
||||
$env->set('dirsep', \DIRECTORY_SEPARATOR);
|
||||
$env->set('homedir', $_SERVER['HOME'] . \DIRECTORY_SEPARATOR);
|
||||
|
||||
$env->set('wd', new CoreFunc('wd', 'Get the current working directory.', 0, 0,
|
||||
fn () => getcwd() . \DIRECTORY_SEPARATOR
|
||||
));
|
||||
|
||||
$env->set('chdir', new CoreFunc('chdir', 'Change working directory.', 1, 1,
|
||||
fn (string $dir) => chdir($dir)
|
||||
));
|
||||
|
||||
$env->set('file?', new CoreFunc('file?', 'Check if file exists.', 1, 1,
|
||||
fn (string $filename) => file_exists($filename)
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user