bhl_validate_func_ref(..) now kinda supports fully namespaced function names: it takes the last item and tries to match it

This commit is contained in:
Pavel Shevaev 2023-11-24 16:32:58 +03:00
parent 6c67e9ab37
commit e4ba8a762f
1 changed files with 18 additions and 13 deletions

View File

@ -102,7 +102,7 @@ function bhl_proj() : BhlProj
return BhlProj::$active;
}
function _bhl_make_abs_path($proj_file, $path)
function _bhl_make_abs_path(string $proj_file, string $path) : string
{
if($path && $path[0] == '.')
return dirname($proj_file) . '/' . $path;
@ -110,18 +110,18 @@ function _bhl_make_abs_path($proj_file, $path)
return $path;
}
function bhl_result_file()
function bhl_result_file() : string
{
return bhl_proj()->result_file;
}
function bhl_dir()
function bhl_dir() : string
{
global $GAME_ROOT;
return "$GAME_ROOT/composer/vendor/bit/bhl";
}
function bhl_shell($cmd, &$ret_var, &$ret_out)
function bhl_shell(string $cmd, &$ret_var, &$ret_out)
{
$prev_path = mono_try_override_path();
@ -135,19 +135,19 @@ function bhl_shell($cmd, &$ret_var, &$ret_out)
}
}
function bhl_shell_ensure($cmd)
function bhl_shell_ensure(string $cmd)
{
bhl_shell($cmd, $ret_var, $ret_out);
if($ret_var !== 0)
throw new Exception("Error executing shell cmd: $ret_var");
}
function bhl_scan_files()
function bhl_scan_files() : array
{
return scan_files_rec(bhl_proj()->src_dirs, array('.bhl'));
}
function bhl_run($debug = true, $force = false, $exit_on_err = true)
function bhl_run(bool $debug = true, bool $force = false, bool $exit_on_err = true)
{
global $GAME_ROOT;
@ -175,7 +175,7 @@ function bhl_run($debug = true, $force = false, $exit_on_err = true)
@touch($result_file);
}
function bhl_handle_error_result(array $ret_out, $err_file, $exit = true)
function bhl_handle_error_result(array $ret_out, string $err_file, bool $exit = true)
{
if(!is_file($err_file))
{
@ -221,7 +221,7 @@ function bhl_clean_cache()
ensure_rm(bhl_proj()->tmp_dir);
}
function bhl_show_position($line, $row, array $lines)
function bhl_show_position(int $line, int $row, array $lines) : string
{
if($line > 0 && $line <= count($lines))
{
@ -241,7 +241,7 @@ function bhl_show_position($line, $row, array $lines)
return "??? @($line:$row)";
}
function bhl_line_row_to_pos($file, $line, $row)
function bhl_line_row_to_pos(string $file, int $line, int $row) : ?int
{
$pos = 0;
$lines = file($file);
@ -254,7 +254,7 @@ function bhl_line_row_to_pos($file, $line, $row)
return $pos;
}
function bhl_map_module_to_file($module)
function bhl_map_module_to_file(string $module) : ?string
{
$bhl_proj = bhl_proj();
foreach($bhl_proj->getIncPath() as $dir)
@ -266,11 +266,16 @@ function bhl_map_module_to_file($module)
return null;
}
function bhl_validate_func_ref($module_file, $func, array $signature)
function bhl_validate_func_ref(string $module_file, string $func_full_name, array $signature)
{
if(sizeof($signature) == 0)
throw new Exception("Signature is invalid");
//NOTE: we can't validate if the function is actually in a namespace
// but was passed without a namespace prefix
$name_items = explode('.', $func_full_name);
$func = end($name_items);
$module_src = file_get_contents($module_file);
if(!$module_src)
@ -301,7 +306,7 @@ function bhl_validate_func_ref($module_file, $func, array $signature)
throw new Exception("Func '$func' signature '".implode(',', $signature)."' not found in module '$module_file'");
}
function bhl_upm_path()
function bhl_upm_path() : string
{
global $GAME_ROOT;
$pkg_dir = get("UNITY_ASSETS_DIR") . '/../Packages/bhl';