diff options
| author | Christine Dodrill <me@christine.website> | 2018-12-08 09:34:00 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2018-12-08 09:34:00 -0800 |
| commit | ceec35812913a70f94029c7933428ab79ca34db0 (patch) | |
| tree | 0fbb9368dd7c346ab4f3f9b19e6eac2ff53f01ac /internal/gluaexpect/expect.go | |
| parent | 28e2d4e4ca734e6b5ffbc07d4f4631c02b003ea9 (diff) | |
| download | x-ceec35812913a70f94029c7933428ab79ca34db0.tar.xz x-ceec35812913a70f94029c7933428ab79ca34db0.zip | |
rescue glue
Diffstat (limited to 'internal/gluaexpect/expect.go')
| -rw-r--r-- | internal/gluaexpect/expect.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/gluaexpect/expect.go b/internal/gluaexpect/expect.go new file mode 100644 index 0000000..b7e57d4 --- /dev/null +++ b/internal/gluaexpect/expect.go @@ -0,0 +1,35 @@ +package gluaexpect + +import ( + "github.com/ThomasRooney/gexpect" + luar "github.com/layeh/gopher-luar" + lua "github.com/yuin/gopher-lua" +) + +func Preload(L *lua.LState) { + L.PreloadModule("expect", Loader) +} + +// Loader is the module loader function. +func Loader(L *lua.LState) int { + mod := L.SetFuncs(L.NewTable(), api) + L.Push(mod) + return 1 +} + +var api = map[string]lua.LGFunction{ + "spawn": spawn, +} + +func spawn(L *lua.LState) int { + cmd := L.CheckString(1) + child, err := gexpect.Spawn(cmd) + if err != nil { + L.Push(lua.LNil) + L.Push(lua.LString(err.Error())) + return 2 + } + + L.Push(luar.New(L, child)) + return 1 +} |
