Skip to content

Add Typeinfo method registration#307

Merged
waynemwashuma merged 6 commits into
wimaengine:devfrom
waynemwashuma:typeinfo-methods
Mar 29, 2026
Merged

Add Typeinfo method registration#307
waynemwashuma merged 6 commits into
wimaengine:devfrom
waynemwashuma:typeinfo-methods

Conversation

@waynemwashuma
Copy link
Copy Markdown
Collaborator

Objective

Extend the reflection system to support runtime method registration and invocation on types.

Solution

The existing reflection system (TypeRegistry / TypeEntry) only stored type metadata (TypeInfo) but lacked support for:

  • Associating callable behavior with types
  • Dynamically invoking methods by name
  • Extending types at runtime with additional functionality

This limited reflection to static inspection without behavioral interaction.

Changes made

  • Added method registry to TypeEntry
    • Maps method.name to MethodEntry
    • Co-locates behavior alongside type metadata
  • Introduced `MethodEntry, a lightweight wrapper around a callable function.

Why this approach

1. Enables behavioral reflection

Moves reflection from introspection-only to introspection + execution

This is critical for:

  • scripting layers
  • editor tooling
  • serialization systems with hooks
  • behavior injection

2. Minimal abstraction overhead

  • MethodEntry is intentionally thin
  • Avoids premature complexity (no binding, context, metadata yet)

3. Extensible foundation

This design allows future additions:

  • Method metadata (signatures, annotations)
  • Context binding (this)
  • Static vs instance methods
  • Type-safe invocation layers

Notes

  • Anonymous functions will not register meaningfully
  • Invocation uses positional arguments (Array)

Showcase

function add(a, b) {
  return a + b
}

const entry = new TypeEntry(info)

entry.setMethod(add)

entry.call("add", [2, 3]) // 5

Direct method access

const method = entry.getMethod("add")

method.call([10, 20]) // 30

Migration guide

No migration required.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Mar 28, 2026
@waynemwashuma waynemwashuma added the type:enhancement New feature or request label Mar 28, 2026
@waynemwashuma waynemwashuma merged commit aff7e94 into wimaengine:dev Mar 29, 2026
7 checks passed
@waynemwashuma waynemwashuma deleted the typeinfo-methods branch March 29, 2026 09:48
waynemwashuma added a commit that referenced this pull request Mar 29, 2026
## Objective

Integrate `copy` / `clone` semantics into the type registry system.

- Registers duplication methods for all ECS components in their
respective modules
- Enables reflection-based systems to invoke component-specific
duplication logic
- This is building upon #307
## Solution

Although `copy` / `clone` methods were introduced on components, they
were not discoverable through the type registry. This adds a way to use
the type registry to clone/copy components in reflection based systems
without needing to know the underlying type.

### Changes made

Added method registrations for ` ``copy` and `clone` across all
registered component types.

### Why this approach

- Enables generic systems to invoke `copy`/`clone` without hardcoding
types
- Aligns duplication with existing metadata-driven workflows

## Showcase

### Before

```js
// Registry cannot perform cloning generically

const info = registry.get(Position2D)

// No way to invoke type-specific copy logic
// Requires manual handling per type
```

### After

```js
const info = registry.get(Position2D)

// Invoke registered method (pseudo-API)
const copy = info.call('copy', source)
```

## Migration guide

No migration required.

## Checklist

- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
@waynemwashuma waynemwashuma restored the typeinfo-methods branch May 12, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:reflect type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant