Documentation
¶
Overview ¶
glel is an expression language for Go. glel is written in Lua programing language.
Index ¶
Constants ¶
const DefaultAllowedFunctions = `` /* 771-byte string literal not displayed */
DefaultAllowedFunctions is a list of allowed builtin functions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Evaler ¶
type Evaler interface {
// Eval evaluates the object with given environments.
Eval(Env) (lua.LValue, error)
// EvalBool evaluates the object as a boolean value with given environments.
EvalBool(Env) (bool, error)
// EvalContext evaluates the object with given environments.
// Note that this function has a performance degradetion
// compared with [Evaler].Eval.
EvalContext(context.Context, Env) (lua.LValue, error)
// EvalContextBool evaluates the object as a boolean value with given environments.
// Note that this function has a performance degradetion
// compared with [Evaler].EvalBool.
EvalContextBool(context.Context, Env) (bool, error)
}
Evaler is an interface that can be evaluatable.
type Expr ¶
type Expr interface {
// Compile compiles a given expression.
// Compiled expression can be cached and goroutine safe.
Compile(expr string) (Evaler, error)
// Close cleanups this object.
Close()
}
Expr is an interface that executes given expressions. Expr is a groutine safe.
type ExprConfig ¶
type ExprConfig struct {
// DisableSandbox disables sandboxing.
DisableSandbox bool
// PoolSize is a size of the Lua VM pool.
// This defaults to 50.
// Pooling is disabled if size is a nevative value.
PoolSize int
// AllowedFunctions is a space separated list of allowed Lua buitin functions.
// This defaults to [DefaultAllowedFunctions].
AllowedFunctions string
// EnvFunc is a function that customizes Lua environment.
// Stack top of given *lua.LState is a table that will be used
// in [Evaler].Eval.
//
// Example:
//
// func(lstate *lua.LState) int {
// env := lstate.CheckTable(1)
// lstate.SetTable(env, lua.LString("key"), lua.LString("value"))
// return 0
// }
//
EnvFunc func(*lua.LState) int
}
ExprConfig is a configurations for Expr.
type ExprOption ¶
type ExprOption func(*ExprConfig)
ExprOption is an option for Expr.
func WithAllowedFunctions ¶
func WithAllowedFunctions(lst string) ExprOption
WithAllowedFunctions is a space separated list of allowed Lua buitin functions. This defaults to DefaultAllowedFunctions.
func WithDisableSandbox ¶ added in v1.1.0
func WithDisableSandbox() ExprOption
WithDisableSandbox disables a sandboxing.
func WithEnv ¶
func WithEnv(env Env) ExprOption
WithEnv is an Env that customizes Lua environment. You can not use both of WithEnv and WithEnvFunc.
func WithEnvFunc ¶
func WithEnvFunc(f func(*lua.LState) int) ExprOption
WithEnvFunc is a function that customizes Lua environment. You can not use both of WithEnv and WithEnvFunc.
func WithPoolSize ¶
func WithPoolSize(size int) ExprOption
WithPoolSize is a size of the Lua VM pool. This defaults to 50. Pooling is disabled if size is a nevative value.