Documentation
¶
Overview ¶
Package emit contains the per-construct emitters for the purego code generator. All emitted files are pure Go — no CGo, no C headers, no .m files.
Index ¶
- Constants
- func BlockGoFuncType(objcType string, ctx typemap.Context, mapper *typemap.Mapper, ...) string
- func ClassMethodGoName(className, selector string) string
- func ClassMethodGoNameFromMeta(className, selector string, m *meta.FrameworkMeta) string
- func EmitClasses(outDir, packageName, framework string, m *meta.FrameworkMeta, ...) error
- func EmitEnums(w io.Writer, framework *meta.FrameworkMeta) error
- func EmitExterns(w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper, ...) (typemap.ImportSet, error)
- func EmitProtocols(w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper, ...) (typemap.ImportSet, error)
- func EmitStructs(w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper) (typemap.ImportSet, error)
- func EmittableFunctions(framework *meta.FrameworkMeta, diag func(format string, args ...any)) []meta.Function
- func FormatGoSource(src []byte) ([]byte, error)
- func FunctionGoName(fn meta.Function) string
- func FunctionWillBeEmitted(fn meta.Function) bool
- func MapEnumGoType(t string) string
- func MethodWillBeEmitted(method meta.Method) bool
- func ReturnIsVoid(retType meta.ReturnType) bool
- func UpgradeEnumTypeIfOverflow(goType string, members []meta.EnumMember) string
- func WriteGoFile(path string, src []byte) error
- type FunctionRegistration
- type RegistrySnapshot
Constants ¶
const ( PureobjcImport = "github.com/deploymenttheory/go-bindings-macosplatform/bindings/runtime/purego" PureobjcPkg = "purego" ObjcImport = "github.com/ebitengine/purego/objc" ObjcPkg = "objc" )
Variables ¶
This section is empty.
Functions ¶
func BlockGoFuncType ¶
func BlockGoFuncType( objcType string, ctx typemap.Context, mapper *typemap.Mapper, imports typemap.ImportSet, ownerIndex map[string]string, ) string
BlockGoFuncType returns the public Go type the raw emitter gives a block-typed parameter: the adapter's closure type, or objc.Block when the block cannot be bridged. Downstream emitters (idiomatic layer) must use this instead of Mapper.GoType so their signatures match the raw bindings.
func ClassMethodGoName ¶
ClassMethodGoName returns the expected exported Go function name for an ObjC class method. The result is className + MethodName(selector), which matches the emitter's output for the common case. Name-collision avoidance may produce a different name in rare cases; tests generated from this name should be treated as best-effort.
("NSBundle", "mainBundle") → "NSBundleMainBundle"
("NSProcessInfo", "processInfo") → "NSProcessInfoProcessInfo"
func ClassMethodGoNameFromMeta ¶
func ClassMethodGoNameFromMeta(className, selector string, m *meta.FrameworkMeta) string
ClassMethodGoNameFromMeta is like ClassMethodGoName but also applies the same name-collision avoidance the emitter uses: if the derived candidate collides with an enum, struct, or class name in the same framework, a "Class" suffix is appended (matching classMethodName in classes.go).
("SFSpeechRecognizer", "authorizationStatus", m) → "SFSpeechRecognizerAuthorizationStatusClass"
("CBManager", "authorization", m) → "CBManagerAuthorizationClass"
func EmitClasses ¶
func EmitClasses( outDir, packageName, framework string, m *meta.FrameworkMeta, mapper *typemap.Mapper, reg *RegistrySnapshot, ) error
EmitClasses writes one .go file per ObjC class in the framework to outDir.
func EmitEnums ¶
func EmitEnums(w io.Writer, framework *meta.FrameworkMeta) error
EmitEnums writes all enum declarations for the framework to w. It gathers each enum into a resolved view and renders the whole set through the enum template.
func EmitExterns ¶
func EmitExterns( w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper, dylibVarName string, ) (typemap.ImportSet, error)
EmitExterns writes accessor functions for extern global symbols. Each extern is accessed via purego.Dlsym at runtime.
func EmitProtocols ¶
func EmitProtocols( w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper, classNameOwner map[string]string, ) (typemap.ImportSet, error)
EmitProtocols writes Go interface types for all ObjC protocols in the framework.
func EmitStructs ¶
func EmitStructs( w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper, ) (typemap.ImportSet, error)
EmitStructs writes all struct type declarations for the framework to w. Returns cross-framework imports discovered during field type resolution.
func EmittableFunctions ¶
func EmittableFunctions( framework *meta.FrameworkMeta, diag func(format string, args ...any), ) []meta.Function
EmittableFunctions returns the free C functions the raw emitter emits for framework, sorted by name. It applies the skip rules (unavailable, inline, non-format variadic, duplicates) and the exported-name collision rules (naming.ExportedFunctionName vs other package-level identifiers). The optional diag callback receives a message for each collision skip; pass nil to filter silently. Downstream emitters (idiomatic layer, genacceptance) must use this so they cannot drift from the raw emission set.
func FormatGoSource ¶
FormatGoSource runs src through go/format (canonical gofmt). It returns an error — failing generation loudly — when src is not valid Go, so an emitter bug surfaces at generation time rather than as broken output on disk.
func FunctionGoName ¶
FunctionGoName returns the exported Go name the emitter uses for a free C function (snake_case names become PascalCase; already-exported C names are unchanged).
func FunctionWillBeEmitted ¶
FunctionWillBeEmitted reports whether a free C function will appear in the generated purego bindings as an exported Go symbol.
It does not account for exported-name collision skips (seedReservedGoNames in EmitFunctions); callers must tolerate rare false positives.
func MapEnumGoType ¶
MapEnumGoType maps an ObjC/C integer type string to the Go integer type used as an enum's underlying type. Exported so the idiomatic emitter can derive the exact same underlying type for its re-emitted concrete enums.
func MethodWillBeEmitted ¶
MethodWillBeEmitted reports whether an ObjC method will appear in the generated purego bindings. It mirrors isMethodBridgeable in classes.go — any changes to the emitter's skip rules must be reflected here.
It does not account for name-collision avoidance (classMethodName), which silently drops class methods whose derived Go name would collide with a package-level type. Those cases are rare and impossible to detect without a full registry load; callers of this function must tolerate rare false positives (a function name that was ultimately not emitted).
func ReturnIsVoid ¶
func ReturnIsVoid(retType meta.ReturnType) bool
ReturnIsVoid reports whether a method's return type is void.
func UpgradeEnumTypeIfOverflow ¶
func UpgradeEnumTypeIfOverflow(goType string, members []meta.EnumMember) string
UpgradeEnumTypeIfOverflow upgrades a signed Go integer type to its unsigned variant when a member value would overflow it. Exported for reuse alongside MapEnumGoType.
func WriteGoFile ¶
WriteGoFile formats src with go/format and writes the canonical result to path. It is the single choke point for every generated .go file so output is always gofmt-canonical and emitters/templates need not hand-manage whitespace, alignment, or import grouping.
Types ¶
type FunctionRegistration ¶
FunctionRegistration pairs a C symbol with its purego.RegisterLibFunc call so the runtime emitter can record per-symbol registration failures.
func EmitFunctions ¶
func EmitFunctions( w io.Writer, framework *meta.FrameworkMeta, mapper *typemap.Mapper, dylibVarName string, ownerIndex map[string]string, ) (imports typemap.ImportSet, regLines []FunctionRegistration, err error)
EmitFunctions writes Go var declarations and wrapper functions for free C functions in the framework. Registration lines (purego.RegisterLibFunc calls) are returned as regLines so they can be embedded in the runtime.go init() AFTER a successful Dlopen — preventing the init-order bug where a separate _functions.go init() would run before _runtime.go's init() and see a zero library handle. ownerIndex maps ObjC class names to their owning framework — used to distinguish ObjC object pointers (need .Ptr()) from C struct pointers. Returns the cross-framework imports discovered and the registration lines.
type RegistrySnapshot ¶
type RegistrySnapshot struct {
OwnerIndex map[string]string
GenericClasses map[string]bool
GenericParamIndex map[string][]string
ClassIndex map[string]meta.Class
BlockedImports map[string]map[string]bool
EnumGoTypeIndex map[string]string // enum name → underlying Go type (e.g. "int64")
ModulePrefix string // Go module path prefix for framework packages
}
RegistrySnapshot carries the cross-framework lookup tables the class emitter needs.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package render turns the raw purego emitter's resolved view (package view) into Go source through templates only.
|
Package render turns the raw purego emitter's resolved view (package view) into Go source through templates only. |
|
Package view holds the pure-data intermediate representation for the raw purego framework emitter.
|
Package view holds the pure-data intermediate representation for the raw purego framework emitter. |