Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LuaCondition ¶
type LuaCondition struct {
// Script contains the Lua code to be executed.
// The script must return a boolean value as its final result.
Script string
}
LuaCondition implements SwitchCondition by evaluating a Lua script. The script is executed in a fresh Lua state for each evaluation and must return a boolean value.
The script has access to the following global variables:
- metadata: A string representation of the thread context's metadata map
- last_message: The content of the last message in the thread (if available)
Example usage:
condition := LuaCondition{
Script: `
-- Check if metadata contains "type=question"
return string.find(metadata, "type=question") ~= nil
`,
}
result, err := condition.Evaluate(threadContext)
func (LuaCondition) Evaluate ¶
func (l LuaCondition) Evaluate(tc minds.ThreadContext) (bool, error)
Evaluate executes the Lua script and returns its boolean result. It creates a new Lua state, populates it with thread context data, executes the script, and interprets the result.
The function provides the following global variables to the Lua environment:
- metadata: String representation of tc.Metadata()
- last_message: Content of the last message in tc.Messages() (if any)
Returns an error if:
- The script execution fails
- The script returns a non-boolean value
Click to show internal directories.
Click to hide internal directories.