lua

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SharedMap sync.Map
)

Shared across all workers

Functions

func Cancel

func Cancel()

func GetRow

func GetRow(rows *sql.Rows) ([]string, error)

sql.Rows.Scan requires pointer args, not sure how to pass that from Lua world, via luar (we can deference a pointer by using '-', not sure how to instruct luar to pass something by pointer). So for now, we can have a helper method that returns a row as an array.

func RowsToJson

func RowsToJson(rows *sql.Rows) []string

Types

type Generator

type Generator struct {
	Script    string
	ScriptDir string
	Args      []string
	L         *lua.LState
	LG        *LG
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(o GeneratorOptions, id int, requestrate int, concurrency int, ctx context.Context, s *stats.Stats) *Generator

func (*Generator) Finish

func (l *Generator) Finish() error

func (*Generator) Init

func (l *Generator) Init() error

func (*Generator) InitDone

func (l *Generator) InitDone() error

func (*Generator) Tick

func (l *Generator) Tick() error

type GeneratorOptions

type GeneratorOptions struct {
	Script string
	Args   []string
	Debug  bool
}

func NewOptions

func NewOptions() *GeneratorOptions

type LG

type LG struct {
	Id          int
	Concurrency int
	Map         *sync.Map
	RequestRate int
	ScriptDir   string
	ScriptArgs  *lua.LTable
	// contains filtered or unexported fields
}

func NewLG

func NewLG(id int, requestrate int, concurrency int, ctx context.Context, script string, s *stats.Stats, log *logrus.Entry) *LG

func (*LG) AbortCustomMetrics

func (lg *LG) AbortCustomMetrics(keys ...string)

func (*LG) BeginCustomMetrics

func (lg *LG) BeginCustomMetrics(keys ...string)

func (*LG) Context

func (lg *LG) Context() context.Context

func (*LG) EndCustomMetrics

func (lg *LG) EndCustomMetrics(keys ...string) error

func (*LG) EndCustomMetricsWithError

func (lg *LG) EndCustomMetricsWithError(keys ...string) error

func (*LG) RecordRawMetrics

func (lg *LG) RecordRawMetrics(key string, value int64)

func (*LG) SetTickDataFile

func (lg *LG) SetTickDataFile(f string)

func (*LG) ShouldQuit

func (lg *LG) ShouldQuit() bool

type MarkovChain

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

MarkovChain contains a map ("chain") of prefixes to a list of suffixes. A prefix is a string of prefixLen words joined with spaces. A suffix is a single word. A prefix can have multiple suffixes.

func NewMarkovChain

func NewMarkovChain(prefixLen int) *MarkovChain

NewMarkovChain returns a new MarkovChain with prefixes of prefixLen words.

func (*MarkovChain) Build

func (c *MarkovChain) Build()

Build reads text from the provided Reader and parses it into prefixes and suffixes that are stored in MarkovChain.

func (*MarkovChain) Generate

func (c *MarkovChain) Generate(n int) string

Generate returns a string of at most n words generated from MarkovChain.

func (*MarkovChain) GenerateText

func (c *MarkovChain) GenerateText(size int, paraNumWords int) string

GenerateText returns a string of >= given size in bytes, with a para for even N words specified

type MarkovPrefix

type MarkovPrefix []string

MarkovPrefix is a Markov chain prefix of one or more words.

func (MarkovPrefix) Shift

func (p MarkovPrefix) Shift(word string)

Shift removes the first word from the MarkovPrefix and appends the given word.

func (MarkovPrefix) String

func (p MarkovPrefix) String() string

String returns the MarkovPrefix as a string (for use as a map key).

Jump to

Keyboard shortcuts

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