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); }
$name = generate_name('Time'); ?> inline TIME <?php echo $name; ?> (const DATETIME& date_time) { return TIME(date_time.Hour(), date_time.Minute(), date_time.Second(), 0); } <?php return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $args, 'result' => $result, 'deterministic' => true]; }); ?> <?php declareFunction('DATETIMEFROMINT', ['BASE::INT'], function ($args) { $result = lookupType('BASE::DATETIME'); $name = generate_name('DateTimeFromInt'); ?> inline DATETIME <?php echo $name; ?> (const INT& seconds) { return DATETIME(seconds); } <?php return ['kind' => 'FUNCTION', 'name' => $name, 'input' => $args, 'result' => $result, 'deterministic' => true]; });
location.FromString(buffer); } inline int ToString(const @type& location, char* buffer) { return location.ToString(bufffer); } inline void FromJson(const Json::Value& src, @type& dest) { dest.FromJson(src); } inline void ToJson(@type& src, Json::Value& dest) { src.ToJson(dest); } <?php $globalContent .= ob_get_clean(); ?> <?php return ['kind' => 'TYPE', 'complex' => false, 'system_headers' => $systemHeaders, 'global_content' => $globalContent, 'constructors' => $constructors, 'methods' => $methods, 'functions' => $functions, 'libraries' => $libraries, 'properties' => [], 'describe_json' => DescribeJson('location'), 'extras' => ['size.bytes' => 24]]; } // Temporarily declare these constructors outside to get around issues with the type system. declareFunction('LOCATION', ['base::double', 'base::double'], function ($args) { $retType = lookupType('BASE::LOCATION'); return ['kind' => 'FUNCITON', 'name' => 'LOCATION', 'input' => $args, 'result' => $retType, 'deterministic' => true]; }); declareFunction('LOCATION', ['base::double', 'base::double', 'base::bool'], function ($args) { $retType = lookupType('BASE::LOCATION'); return ['kind' => 'FUNCITON', 'name' => 'LOCATION', 'input' => $args, 'result' => $retType, 'deterministic' => true]; });
<?php // Copyright 2014 Tera Insights, LLC. All Rights Reserved. // Declares a function 'Ord' that takes a string literal and returns the first // character as a byte. declareFunction('Ord', ['base::STRING_LITERAL'], function () { $inputType = lookupType('base::STRING_LITERAL'); $outputType = lookupType('base::BYTE'); $inputs = [$inputType]; echo $outputType; ?> Ord( const <?php echo $inputType; ?> & str ) { return str[0]; } <?php return ['type' => 'FUNCTION', 'input' => $inputs, 'result' => $outputType, 'deterministic' => true]; });