File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ func mains() error {
127127 L .SetGlobal ("spawnctx" , L .NewFunction (SpawnContext ))
128128 L .SetGlobal ("kill" , L .NewFunction (Kill ))
129129 L .SetGlobal ("wait" , L .NewFunction (Wait ))
130+ L .SetGlobal ("shot" , L .NewFunction (Shot ))
130131
131132 table := L .NewTable ()
132133 for i , s := range flag .Args () {
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "github.com/yuin/gopher-lua"
5+
6+ "github.com/hymkor/expect/internal/go-console/output"
7+ )
8+
9+ func shot (n int ) ([]string , error ) {
10+ if ! useStderrOnGetRecentOutput {
11+ result , err := consoleoutput .GetRecentOutputByStdout (n )
12+ if err == nil {
13+ return result , nil
14+ }
15+ useStderrOnGetRecentOutput = true
16+ }
17+ return consoleoutput .GetRecentOutputByStderr (n )
18+ }
19+
20+ func Shot (L * lua.LState ) int {
21+ n , ok := L .Get (- 1 ).(lua.LNumber )
22+ if ! ok {
23+ L .Push (lua .LNil )
24+ L .Push (lua .LString ("Expected a number" ))
25+ return 2
26+ }
27+ result , err := shot (int (n ))
28+ if err != nil {
29+ L .Push (lua .LNil )
30+ L .Push (lua .LString (err .Error ()))
31+ return 2
32+ }
33+ table := L .NewTable ()
34+ for i , line := range result {
35+ L .SetTable (table , lua .LNumber (i + 1 ), lua .LString (line ))
36+ }
37+ L .Push (table )
38+ return 1
39+ }
You can’t perform that action at this time.
0 commit comments