diff --git a/.gitignore b/.gitignore index c8e7988f..2e30e089 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ cmake-build-debug .idea docs /.vs + +# tools +tools/raylib_api.json diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 00000000..194ef518 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,15 @@ +## `see_missing.py` + +### Usage + +[Download](https://github.com/raysan5/raylib/blob/master/tools/rlparser/output/raylib_api.json) or generate a `raylib_api.json` file (via [rlparser](https://github.com/raysan5/raylib/tree/master/tools/rlparser)) and place it in the `/tools` directory. + +Run the script with an appropriate Python 3 executable: + +```shell +$ python3 see_missing.py +``` + +The script will list all raylib functions it couldn't find in the `.hpp` files under `/include`, along with their parameters. + +It searches for `::(`. Make sure to prefix downstream raylib calls with `::`. diff --git a/tools/see_missing.py b/tools/see_missing.py new file mode 100755 index 00000000..6d9508d8 --- /dev/null +++ b/tools/see_missing.py @@ -0,0 +1,47 @@ +#!/usr/bin/python3 + +""" +lists missing calls to raylib functions + +usage: python3 see_missing.py +""" + +import json +import sys +from pathlib import Path + + +def print_err(*args, **kwargs) -> None: + print(*args, file=sys.stderr, **kwargs) + + +def main() -> int: + raylib_api_path = Path("raylib_api.json") + if not raylib_api_path.exists(): + print_err("raylib_api.json not found" + "\n\nget it at raylib/tools/rlparser/output") + return 1 + + raylib_api: dict[str, list] = json.loads(raylib_api_path.read_text()) + raylib_funcs: dict[str, dict] = {func["name"]: func for func in raylib_api["functions"]} + + raylib_cpp_files: list[Path] = list(Path("../include").glob("**/*.hpp")) + raylib_cpp_combined: str = "\n".join(x.read_text() for x in raylib_cpp_files) + + found_func_calls: int = 0 + print("\n\nmissing calls for:\n") + for func_name, func in raylib_funcs.items(): + if f"::{func_name}(" in raylib_cpp_combined: + found_func_calls += 1 + continue + params = ", ".join(f"{param["type"]} {param["name"]}" for param in func.get("params", {})) + print_err(f"::{func_name}({params})") + + percentage: float = round((found_func_calls / len(raylib_funcs)) * 100, 2) + print(f"\n{found_func_calls}/{len(raylib_funcs)} implemented ({percentage}%)") + + return 0 + + +if __name__ == "__main__": + sys.exit(main())