Skip to content

Commit 5aeaeab

Browse files
authored
Merge pull request yuin#291 from joesonw/master
allowing check if LState is closed
2 parents 376fb27 + 0efbd4d commit 5aeaeab

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module github.com/yuin/gopher-lua
22

3+
go 1.14
4+
35
require (
46
github.com/chzyer/logex v1.1.10 // indirect
57
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e

state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,10 @@ func NewState(opts ...Options) *LState {
13671367
return ls
13681368
}
13691369

1370+
func (ls *LState) IsClosed() bool {
1371+
return ls.stack == nil
1372+
}
1373+
13701374
func (ls *LState) Close() {
13711375
atomic.AddInt32(&ls.stop, 1)
13721376
for _, file := range ls.G.tempFiles {

state_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"time"
88
)
99

10+
func TestLStateIsClosed(t *testing.T) {
11+
L := NewState()
12+
L.Close()
13+
errorIfNotEqual(t, true, L.IsClosed())
14+
}
15+
1016
func TestCallStackOverflowWhenFixed(t *testing.T) {
1117
L := NewState(Options{
1218
CallStackSize: 3,

0 commit comments

Comments
 (0)