Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco WASM Structs

From Leeroopedia
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

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

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment