Implementation:Google deepmind Mujoco WASM Structs
| Knowledge Sources | |
|---|---|
| Domains | WebAssembly, Code Generation, Struct Bindings |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Generates Embind bindings for MuJoCo structs, producing C++ wrapper classes with property accessors for JavaScript interop.
Description
structs.py contains the code generation logic for creating Embind struct bindings. It defines WrappedFieldData (a dataclass for field binding, declaration, pointer initialization, copy reset, and type information) and provides _get_property_binding for generating C++ property accessor code and _generate_field_data for producing complete field definitions. The generator handles primitive fields, fixed-size arrays, pointer fields requiring wrapper initialization, and manually handled special-case fields. It determines struct ordering based on type dependencies to ensure correct compilation order.
Usage
Called during the WASM code generation pipeline to produce the struct wrapper sections of the bindings.cc file, translating MuJoCo C struct definitions into JavaScript-accessible Embind classes.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: wasm/codegen/generators/structs.py
- Lines: 1-830
Key Functions
@dataclasses.dataclass
class WrappedFieldData:
binding: str = ""
declaration: str = ""
ptr_initialization: str = ""
ptr_copy_reset: str = ""
is_primitive_or_fixed_size: bool = False
typename: str = ""
def _get_property_binding(field, struct_wrapper_name, setter=False, reference=False) -> str:
def _generate_field_data(field, struct_wrapper_name) -> WrappedFieldData:
Import
from wasm.codegen.generators import structs
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| field | ast_nodes.StructFieldDecl | Yes | Struct field declaration from introspection AST |
| struct_wrapper_name | str | Yes | Name of the C++ wrapper class being generated |
Outputs
| Name | Type | Description |
|---|---|---|
| WrappedFieldData | WrappedFieldData | Complete field binding and declaration code |
| str | str | Generated C++ code for property binding or field definition |