How maxime-pages/fabgen works
Project Type and Key Purpose
• Fabgen is essentially a code generation tool that converts user-provided API binding scripts into binding code tailored for different target languages.
• Its primary components include the generic binding generator (implemented in gen.py), language-specific binding implementations (found in the “lang” directory), and additional library code (in the “lib” directory) that supports standard C++ constructs such as STL, and even additional functionalities like proxying and feature-based extensions.
• The tool is further validated via a comprehensive set of tests and CI configurations (e.g., Travis CI files, Coveralls).
Main Components
a. User Input Layer:
• API Binding Script – the Python script provided by the user that describes what C++ functions, classes, etc., to bind.
• bind.py – the main entry point that routes to appropriate language-specific binding generators based on the provided CLI options.
b. Core Generator:
• gen.py – the central generic binding generator that encapsulates most of the core logic.
• Feature Extension Mechanism – includes support for additional features such as proxy, arg_out, and more as explained in the README.
c. Language-Specific Handlers:
• “lang” Directory – contains separate modules (cpython.py, lua.py, go.py, xml.py) for handling language-specific conversion rules.
• “lib” Directory – provides low-level common and language-specific support code (with similar subdirectories for cpython, lua, go, xml) which further abstract C++ standard library constructs and simplify the binding generation.
d. Testing and Examples:
• “tests” Directory and tests.py – verify correct binding generation and ensure the robustness of the tool.
• “examples” Directory – demonstrates usage, such as a sample binding for Harfang Multimedia Framework usage.
e. External Components:
• CI/CD and dependency files, including Travis CI configuration and requirements.txt.
Relationships and Data Flow
• The user invokes bind.py with an API binding script and options (such as --cpython, --lua, or --go).
• bind.py calls the generic generator (gen.py) which orchestrates the process.
• The generator then leverages language-specific modules in the “lang” directory to convert C++ constructs into target language bindings.
• Underlying type conversion details and additional functionalities are provided via modules in the “lib” directory.
• Output (target binding code) is produced and may then be deployed, tested, or further compiled.
• The tests directory ensures that all conversion and binding productions meet expected behaviors.
Architectural Patterns & Design Principles
• Modular Design: Separation between the core generator logic (gen.py) and language-specific conversion logic (modules under “lang” and “lib”).
• Extensibility: The feature mechanism (with proxies, type converters, and extended function prototypes) allows additional behaviors without needing to change the core generator.
• Abstraction & Reuse: The “lib” folder abstracts out common and language-specific conversions (std, stl routines) to keep the generic parts (in gen.py) simple and maintainable.