tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

common.php (666B)


      1 <?php
      2 declare(strict_types=1);
      3 namespace Arboricx;
      4 require_once __DIR__.'/ffi.php';
      5 
      6 function readBundle(string $path): string
      7 {
      8     $bytes = file_get_contents($path);
      9     if ($bytes === false) throw new \RuntimeException("Cannot read bundle: $path");
     10     return $bytes;
     11 }
     12 
     13 function render(Context $ctx, \FFI\CData $value, string $format): string
     14 {
     15     return match ($format) {
     16         'string' => $ctx->toString($value),
     17         'number' => $ctx->toNumber($value),
     18         'bool' => $ctx->toBool($value) ? 'true' : 'false',
     19         'bytes' => bin2hex($ctx->toBytes($value)),
     20         default => throw new \InvalidArgumentException('invalid result format'),
     21     };
     22 }