modules

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanRuntime

func CleanRuntime(src string) string

CleanRuntime strips //go:build directives, the package declaration, and import blocks from Go source so it can be emitted into a generated program.

func CollectGoDeps

func CollectGoDeps(moduleNames []string) []string

CollectGoDeps returns all GoDeps from the named modules (deduped, sorted).

func IsModule

func IsModule(name string) bool

IsModule returns true if name is a registered module.

func LookupFunc

func LookupFunc(module, funcName string) (string, bool)

LookupFunc resolves a module function to its Go runtime wrapper name.

func Names

func Names() []string

Names returns sorted names of all registered modules.

func Register

func Register(m *Module)

Register adds a module to the global registry.

Types

type ArgType

type ArgType int

ArgType represents the expected type of a function argument.

const (
	String ArgType = iota
	Int
	Float
	Bool
	Any
)

type FuncDef

type FuncDef struct {
	// Name is the rugo function name (e.g. "exec").
	Name string
	// Args lists the expected typed arguments. The wrapper will convert
	// interface{} args to these types before calling the implementation.
	Args []ArgType
	// Variadic, when true, passes remaining args beyond Args as ...interface{}.
	// The implementation function should accept extra ...interface{} as its last parameter.
	Variadic bool
	// Doc is the documentation string shown by `rugo doc`.
	Doc string
}

FuncDef describes a function exposed by a module. The implementation function must be named <module>_<Name> in runtime.go and use typed parameters matching Args (e.g. func os_exec(command string) interface{}).

type Module

type Module struct {
	// Name is the rugo import name (e.g. "os", "http", "conv").
	Name string
	// Type is the Go struct type name used as the method receiver (e.g. "OS", "HTTP").
	Type string
	// Funcs describes the functions this module exposes.
	Funcs []FuncDef
	// GoImports lists additional Go imports this module needs beyond the base set.
	GoImports []string
	// GoDeps lists Go module dependencies (require lines for go.mod) that the
	// generated program needs. Each entry should be "module version", e.g.
	// "github.com/gosimple/slug v1.15.0". Only needed for external modules
	// that depend on third-party Go packages.
	GoDeps []string
	// Runtime is the Go source for the struct type and its methods (from embedded runtime.go).
	Runtime string
	// DispatchEntry, when set, names the module function that triggers dispatch.
	// The compiler generates a typed map (rugo_<mod>_dispatch) mapping user-defined
	// function names to their Go implementations, which the module's runtime uses
	// to route commands to handlers.
	DispatchEntry string
	// Doc is the module-level documentation shown by `rugo doc`.
	Doc string
}

Module represents a Rugo stdlib module that can be imported.

func Get

func Get(name string) (*Module, bool)

Get returns a registered module by name.

func (*Module) FullRuntime

func (m *Module) FullRuntime() string

FullRuntime returns the complete runtime source: the struct type and methods from Runtime plus auto-generated wrappers that handle interface{} conversion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL