Conversation
Introduce GoFFI, a bridge that derives a Dang Module from a Go reflect.Type, wraps live Go values as Dang Values, and invokes Go methods from Dang code. This is a sibling to the GraphQL/Dagger import path, targeting the same Module/ModuleValue/Value model from a different source, so that embedders can expose in-process Go types to scripting code without routing through GraphQL. RegisterType installs a type as a class and is recursion-safe by caching the Module before walking fields. WrapGoValue produces a ModuleValue with lazy field access and Callable method entries, so field selection, method binding, and type checking come for free. Primitives, pointers, slices, and structs map by default; interfaces require a registered Converter; trailing error returns raise a BasicError; void mutators and multi-return methods are skipped to stay robust against arbitrary types. Go reflection cannot recover parameter names, so method arguments are named positionally (arg1, arg2, ...); no-arg methods, the common case, are unaffected and remain auto-callable. Signed-off-by: Alex Suraci <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
GoFFI, a reflection-driven bridge that exposes arbitrary Go typesand values to Dang code: it derives a Dang
Modulefrom areflect.Type, wraps a live Go value as a DangValue, and invokes Gomethods from Dang. This implements phases 1–2 of
go-ffi.md(theDang-side MVP plus interface bridging).
It's a sibling to the GraphQL/Dagger import path — same target (Dang's
Module/ModuleValue/Valuemodel), different source — so embedderscan expose in-process Go types to scripting code without routing through
GraphQL.
Public API
GoFFI(zero value usable) with a configurableNameMapper.Converter{DangType, ToDang, FromDang}+RegisterConverter, forbridging interfaces and host-specific types.
RegisterType(env, reflect.Type) (*Module, error)— idempotent andrecursion-safe (caches the
*Modulebefore walking fields).WrapGoValue(any) (Value, error).DefaultNameMapper(PascalCase → camelCase;URL→url,HTMLBody→htmlBody).WrapGoValueproduces a*ModuleValuewith lazy field entries andCallablemethods, so field access, method binding, and type checkingcome for free from the existing
Select.Evalmachinery.Mapping rules
Primitives, pointers (nullable), slices, and structs (recursively
registered) map by default. Interfaces require a registered
Converter.Trailing
errorreturns raise aBasicError. Void mutators andmulti-return methods are skipped so registering arbitrary types stays
robust.
Note
Go reflection cannot recover parameter names, so method arguments are
named positionally (
arg1,arg2, …). No-arg methods — the commonBooklit case — are unaffected and remain auto-callable.
Tests
10 tests cover the name mapper, type-derivation schemes, field access
and auto-called/argument'd method calls through the full
parse→infer→eval pipeline,
(T, error)raising and catching, recursivetypes, the unregistered-interface error, an interface
Converter, andthe wrap-before-register error.
Phases 3–4 (Booklit integration) are separate, consumer-side follow-ups.