Compare commits
No commits in common. "master" and "v4.0.0" have entirely different histories.
118
bhl.inc.php
118
bhl.inc.php
|
@ -12,6 +12,10 @@ task('bhl_clean_cache', function()
|
||||||
bhl_clean_cache();
|
bhl_clean_cache();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
task('bhl_make_upm_package', function() {
|
||||||
|
bhl_make_upm_package();
|
||||||
|
});
|
||||||
|
|
||||||
class BhlProj
|
class BhlProj
|
||||||
{
|
{
|
||||||
public static ?BhlProj $active = null;
|
public static ?BhlProj $active = null;
|
||||||
|
@ -156,9 +160,11 @@ function bhl_run(bool $debug = true, bool $force = false, bool $exit_on_err = tr
|
||||||
if(!$exit_on_err)
|
if(!$exit_on_err)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if($debug)
|
else
|
||||||
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . ", CRC " . hexdec(hash_file('CRC32', $result_file, false)) . "\n";
|
echo "BHL BUNDLE: total " . kb_len(filesize($result_file)) . ", CRC " . hexdec(hash_file('CRC32', $result_file, false)) . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@touch($result_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit = true)
|
function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit = true)
|
||||||
|
@ -199,7 +205,7 @@ function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit =
|
||||||
function bhl_clean()
|
function bhl_clean()
|
||||||
{
|
{
|
||||||
bhl_clean_cache();
|
bhl_clean_cache();
|
||||||
bhl_shell("clean", $ret, $out);
|
bhl_shell_ensure("clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
function bhl_clean_cache()
|
function bhl_clean_cache()
|
||||||
|
@ -262,30 +268,28 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
|
||||||
$namespace = implode('.', $name_items);
|
$namespace = implode('.', $name_items);
|
||||||
|
|
||||||
$module_src = file_get_contents($module_file);
|
$module_src = file_get_contents($module_file);
|
||||||
$module_src = _bhl_remove_comments($module_src);
|
|
||||||
|
|
||||||
if(!$module_src)
|
if(!$module_src)
|
||||||
throw new Exception("Bad module file '{$module_file}'");
|
throw new Exception("Bad module file '{$module_file}'");
|
||||||
|
|
||||||
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
|
||||||
|
|
||||||
$module_chunks = array();
|
$module_chunks = array();
|
||||||
if($namespace)
|
if($namespace)
|
||||||
{
|
{
|
||||||
if(!isset($ns_chunks[$namespace]))
|
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
||||||
throw new Exception("No namespace '$namespace' found in '$module_file'");
|
if(count($ns_chunks) == 0)
|
||||||
|
throw new Exception("No namespaces found in '$module_file'");
|
||||||
|
|
||||||
foreach($ns_chunks[$namespace] as $ns_src)
|
foreach($ns_chunks as $ns => $ns_src)
|
||||||
|
{
|
||||||
|
if($ns === $namespace)
|
||||||
$module_chunks[] = $ns_src;
|
$module_chunks[] = $ns_src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count($module_chunks) == 0)
|
||||||
|
throw new Exception("Namespace '$namespace' for func '$func_full_name' not found in '$module_file'");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
$module_chunks[] = $module_src;
|
||||||
if(!isset($ns_chunks['']))
|
|
||||||
throw new Exception("No global namespace found in '$module_file'");
|
|
||||||
|
|
||||||
foreach($ns_chunks[''] as $ns_src)
|
|
||||||
$module_chunks[] = $ns_src;
|
|
||||||
}
|
|
||||||
|
|
||||||
$signature_pattern = '';
|
$signature_pattern = '';
|
||||||
$signature_pattern .= '~func\s+';
|
$signature_pattern .= '~func\s+';
|
||||||
|
@ -317,23 +321,6 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
|
||||||
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
|
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bhl_remove_comments(string $txt) : string
|
|
||||||
{
|
|
||||||
//block comments
|
|
||||||
if(strpos($txt, '/*') !== false)
|
|
||||||
{
|
|
||||||
$regex = '~/\*.*?\*/~s';
|
|
||||||
$txt = preg_replace_callback(
|
|
||||||
$regex,
|
|
||||||
//preserve the new lines for better error reporting
|
|
||||||
function($m) { return str_repeat("\n", substr_count($m[0], "\n")); },
|
|
||||||
$txt);
|
|
||||||
}
|
|
||||||
//line comments
|
|
||||||
$txt = preg_replace("~\s*(?<!:)//.*~", "\n", $txt);
|
|
||||||
return $txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _bhl_split_by_namespaces(string $src) : array
|
function _bhl_split_by_namespaces(string $src) : array
|
||||||
{
|
{
|
||||||
$nss = array();
|
$nss = array();
|
||||||
|
@ -347,19 +334,70 @@ function _bhl_split_by_namespaces(string $src) : array
|
||||||
{
|
{
|
||||||
$ns = trim(substr(ltrim($chunk), 9));
|
$ns = trim(substr(ltrim($chunk), 9));
|
||||||
$body = $chunks[$i+1];
|
$body = $chunks[$i+1];
|
||||||
if(!isset($nss[$ns]))
|
$nss[$ns] = $body;
|
||||||
$nss[$ns] = array();
|
|
||||||
$nss[$ns][] = $body;
|
|
||||||
$i+=2;
|
$i+=2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if(!isset($nss['']))
|
|
||||||
$nss[''] = array();
|
|
||||||
$nss[''][] = $chunk;
|
|
||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $nss;
|
return $nss;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bhl_upm_path() : string
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
$pkg_dir = get("UNITY_ASSETS_DIR") . '/../Packages/bhl';
|
||||||
|
return $pkg_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_clean_upm_package()
|
||||||
|
{
|
||||||
|
ensure_rm(bhl_upm_path() . '/Runtime/code/');
|
||||||
|
}
|
||||||
|
|
||||||
|
function bhl_make_upm_package()
|
||||||
|
{
|
||||||
|
global $GAME_ROOT;
|
||||||
|
|
||||||
|
$pkg_dir = bhl_upm_path();
|
||||||
|
ensure_mkdir($pkg_dir);
|
||||||
|
|
||||||
|
$srcs = array();
|
||||||
|
$lines = file(bhl_dir() . '/bhl.cs');
|
||||||
|
$started = false;
|
||||||
|
foreach($lines as $line)
|
||||||
|
{
|
||||||
|
if(!$started && strpos($line, 'static readonly string[] VM_SRC = new string[] {') !== false)
|
||||||
|
{
|
||||||
|
$started = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if($started && strpos($line, '};') !== false)
|
||||||
|
break;
|
||||||
|
else if($started)
|
||||||
|
{
|
||||||
|
$mask = trim($line);
|
||||||
|
$mask = str_replace('$"{BHL_ROOT}/', '', $mask);
|
||||||
|
$mask = str_replace('",', '', $mask);
|
||||||
|
$srcs = array_merge($srcs, glob(bhl_dir() . '/' . $mask));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$trgs = array();
|
||||||
|
$changed = false;
|
||||||
|
foreach($srcs as $src)
|
||||||
|
{
|
||||||
|
$trg = $pkg_dir . '/Runtime/code/' . str_replace(bhl_dir(), '', $src);
|
||||||
|
if(!is_file($trg) || file_get_contents($src) != file_get_contents($trg))
|
||||||
|
$changed = true;
|
||||||
|
$trgs[$src] = $trg;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($changed)
|
||||||
|
{
|
||||||
|
bhl_clean_upm_package();
|
||||||
|
foreach($trgs as $src => $trg)
|
||||||
|
ensure_copy($src, $trg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
namespace metagen_php;
|
namespace metagen_php;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
function flt_bhl_ref($val, $name, $data, $str_args)
|
function flt_bhl_ref($val, $name, $struct, $str_args)
|
||||||
{
|
{
|
||||||
if(!$val)
|
if(!$val)
|
||||||
return $val;
|
return $val;
|
||||||
|
|
Loading…
Reference in New Issue