Documentation
¶
Index ¶
- func CompileScript(source string, name string) (*lua.FunctionProto, error)
- func GoToLua(L *lua.LState, value any) lua.LValue
- func LoadProto(L *lua.LState, proto *lua.FunctionProto) error
- func LuaToGo(lv lua.LValue) interface{}
- func ValidateFunction(proto *lua.FunctionProto, functionName string) error
- type ConfigService
- type ConfigSource
- type HTTPService
- type HTTPServiceOption
- type JSONService
- type MapConfigSource
- type RequestOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompileScript ¶
func CompileScript(source string, name string) (*lua.FunctionProto, error)
CompileScript parses and compiles a Lua script to bytecode. The returned lua.FunctionProto is immutable and safe to share across goroutines and LState instances.
func LoadProto ¶
func LoadProto(L *lua.LState, proto *lua.FunctionProto) error
LoadProto loads a pre-compiled lua.FunctionProto into an LState and executes its top-level chunk, which typically defines global functions.
func ValidateFunction ¶
func ValidateFunction(proto *lua.FunctionProto, functionName string) error
ValidateFunction loads a pre-compiled script into a temporary LState and verifies that executing it defines a global function with the given name.
Types ¶
type ConfigService ¶
type ConfigService struct {
// contains filtered or unexported fields
}
ConfigService provides access to configuration values in Lua scripts
func NewConfigService ¶
func NewConfigService(source ConfigSource) *ConfigService
NewConfigService creates a new config service with the given configuration source
func (*ConfigService) Register ¶
func (s *ConfigService) Register(L *lua.LState)
Register adds the config service to the Lua state Usage in Lua:
local value = config.get("key")
local value = config.get("key", "default_value")
local exists = config.has("key")
type ConfigSource ¶
type ConfigSource interface {
// Get retrieves a configuration value by key
// Returns the value and true if found, or nil and false if not found
Get(key string) (any, bool)
// Keys returns all available configuration keys
Keys() []string
}
ConfigSource is an interface for retrieving configuration values Implementations can back this with environment variables, config files, etc.
func NewMapConfigSource ¶
func NewMapConfigSource(values map[string]any) ConfigSource
NewMapConfigSource creates a ConfigSource backed by a map
type HTTPService ¶
type HTTPService struct {
// contains filtered or unexported fields
}
HTTPService provides HTTP client functionality to Lua scripts.
func NewHTTPService ¶
func NewHTTPService(ctx context.Context, client *http.Client, opts ...HTTPServiceOption) (*HTTPService, error)
NewHTTPService creates a new HTTP service. ctx is required and propagated to every outgoing request, enabling cancellation, tracing, and request-ID propagation. client is the fully-configured HTTP client (auth, timeout, transport already set) and must not be nil. Optional settings are provided via HTTPServiceOption.
func (*HTTPService) Register ¶
func (s *HTTPService) Register(L *lua.LState)
Register adds the HTTP service to the Lua state Usage in Lua:
local response = http.get("https://api.example.com/data")
local response = http.post("https://api.example.com/data", "request body", {["Content-Type"] = "application/json"})
type HTTPServiceOption ¶
type HTTPServiceOption func(*httpServiceConfig)
HTTPServiceOption configures optional settings for NewHTTPService.
func WithRequestOptions ¶
func WithRequestOptions(ro RequestOptions) HTTPServiceOption
WithRequestOptions sets a function that processes requests before sending.
type JSONService ¶
type JSONService struct{}
JSONService provides JSON encoding/decoding functionality to Lua scripts
func (*JSONService) Register ¶
func (s *JSONService) Register(L *lua.LState)
Register adds the JSON service to the Lua state Usage in Lua:
local obj = json.decode('{"key": "value"}')
local str = json.encode({key = "value"})
type MapConfigSource ¶
type MapConfigSource struct {
// contains filtered or unexported fields
}
MapConfigSource is a simple in-memory implementation of ConfigSource
func (*MapConfigSource) Get ¶
func (m *MapConfigSource) Get(key string) (any, bool)
Get retrieves a value from the map
func (*MapConfigSource) Keys ¶
func (m *MapConfigSource) Keys() []string
Keys returns all keys in the map
type RequestOptions ¶
RequestOptions is a function that can modify a request before it is sent. This can be used to add authentication headers, modify URLs, etc.