glua

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldInfo

type FieldInfo struct {
	Name    string // The field name (from JSON tag)
	TypeKey string // The Lua type annotation (e.g., "string", "number", "corev1.Container")
	IsArray bool   // Whether this field is an array
}

FieldInfo: stores information about a struct field for Lua stub generation

type Translator

type Translator struct{}

Translator: handles conversion between Go values and Lua values

func NewTranslator

func NewTranslator() *Translator

NewTranslator: creates a new Translator instance

func (*Translator) FromLua

func (t *Translator) FromLua(L *lua.LState, lv lua.LValue, output interface{}) error

FromLua: converts a Lua value to a Go value. Works similar to json.Unmarshal - pass a state, Lua value and output object. The conversion process:

  1. Create Go value from Lua value (map[string]interface{} for tables, primitives for others)
  2. Marshal the value to JSON
  3. Unmarshal JSON into output object

func (*Translator) ToLua

func (t *Translator) ToLua(L *lua.LState, o interface{}) (lua.LValue, error)

ToLua: converts an arbitrary Go value to a Lua value. It supports primitive types (string, int64, etc.) and complex structs. The conversion process:

  1. Marshal the object to JSON
  2. Unmarshal into map[string]interface{}
  3. Use reflect to walk the map and populate LTable

type TypeInfo

type TypeInfo struct {
	Name       string                // The Lua-friendly type name (e.g., "corev1.Pod")
	GoType     reflect.Type          // The original Go type
	Fields     map[string]*FieldInfo // Map of field name to field information
	IsArray    bool                  // Whether this is an array type
	ElementKey string                // For arrays, the type key of the element
}

TypeInfo: stores information about a registered Go type for Lua stub generation

type TypeRegistry

type TypeRegistry struct {
	// contains filtered or unexported fields
}

TypeRegistry: manages type registration and stub generation for Lua. It processes Go types recursively and generates Lua LSP annotations.

func NewTypeRegistry

func NewTypeRegistry() *TypeRegistry

NewTypeRegistry: creates a new TypeRegistry instance

func (*TypeRegistry) GenerateStubs

func (r *TypeRegistry) GenerateStubs() (string, error)

GenerateStubs: generates Lua annotation stubs for all registered types. Returns a string containing ---@class and ---@field annotations.

Example output:

---@class corev1.Pod
---@field metadata corev1.ObjectMeta
---@field spec corev1.PodSpec

func (*TypeRegistry) Process

func (r *TypeRegistry) Process() error

Process: processes all registered types and discovers dependencies. Call this after registering all root types with Register().

func (*TypeRegistry) Register

func (r *TypeRegistry) Register(obj interface{}) error

Register: adds a Go type to the registry for stub generation. The object is queued for processing to discover all dependent types. Returns an error if the object is nil or not a valid type.

Jump to

Keyboard shortcuts

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