function _defineStdMathFunction($name, $args, $ret, $lib) { $f = function () use($name, $args, $ret, $lib) { $inputs = []; $count = 0; foreach ($args as $arg) { $inputs['arg' . $count] = lookupType($arg); $count += 1; } $retType = lookupType($ret); $hash = \grokit\hashComplex(['BASE::' . $name, $args, $ret]); ?> inline <?php echo $retType; ?> <?php echo $name; ?> ( <?php echo typed_args($inputs); ?> ) { return std::<?php echo $name; ?> (<?php echo args($inputs); ?> ); } <?php return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $inputs, 'result' => $retType, 'deterministic' => true, 'system_headers' => $lib, 'hash' => $hash]; }; declareFunction($name, $args, $f); }
default_params(); // default args with array and NULL function default_extra_params($name, $surname = NULL, $skills = array()) { echo "name {$name}" . PHP_EOL; echo "surname {$surname}" . PHP_EOL; var_dump($skills); } default_extra_params("test"); // typed arguments function typed_args(array $names) { echo count($names) . PHP_EOL; } //typed_args("hello"); // throws a fatal error typed_args([10, 20, 30]); class A { } class B extends A { } class C { } function class_typed_args(A $a) { echo get_class($a) . PHP_EOL; } class_typed_args(new A()); class_typed_args(new B());
function interface_function($name, $type, $args) { global $__grokit_if_name; global $__grokit_if_parent; global $__grokit_if_pointer; ?> <?php echo $type; ?> <?php echo $name; ?> ( <?php echo typed_args($args); ?> ) { <?php echo $__grokit_if_name; ?> Imp& obj = dynamic_cast< <?php echo $__grokit_if_name; ?> Imp& >( *<?php echo $__grokit_if_pointer; ?> ); return obj.<?php echo $name; ?> ( <?php echo args($args); ?> ); } <?php }