conversion functions

This commit is contained in:
Pekka Laiho 2020-05-31 20:55:22 +07:00
parent bde31f9eb3
commit b0f22a19fe

View File

@ -14,6 +14,24 @@ class Types implements ILib
{ {
public function register(Env $env): void public function register(Env $env): void
{ {
// Conversions
$env->set('to-bool', new CoreFunc('to-bool', 'Convert argument to boolean.', 1, 1,
fn ($a) => boolval($a)
));
$env->set('to-float', new CoreFunc('to-float', 'Convert argument to float.', 1, 1,
fn ($a) => floatval($a)
));
$env->set('to-int', new CoreFunc('to-int', 'Convert argument to integer.', 1, 1,
fn ($a) => intval($a)
));
$env->set('to-str', new CoreFunc('fn?', 'Convert argument to string.', 1, 1,
fn ($a) => strval($a)
));
// Test types // Test types
$env->set('type?', new CoreFunc('type?', 'Return the type of argument as a string.', 1, 1, $env->set('type?', new CoreFunc('type?', 'Return the type of argument as a string.', 1, 1,