residentsleeper/scripting/regexp/regexp.go

31 lines
470 B
Go
Raw Normal View History

package regexp
import (
lua "github.com/yuin/gopher-lua"
luar "layeh.com/gopher-luar"
"regexp"
)
func Loader(L *lua.LState) int {
// register functions to the table
mod := L.SetFuncs(L.NewTable(), exports)
// returns the module
L.Push(mod)
return 1
}
var exports = map[string]lua.LGFunction{
"MustCompile": compileFunc,
}
func compileFunc(L *lua.LState) int {
str := L.CheckString(1)
re := regexp.MustCompile(str)
L.Push(luar.New(L, re))
return 1
}