Skip to content

Commit 36862c5

Browse files
authored
Merge pull request yuin#276 from cc682/master
LState.CheckString should cast number to string and return
2 parents ab39c60 + a519e4d commit 36862c5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

auxlib.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func (ls *LState) CheckString(n int) string {
4848
v := ls.Get(n)
4949
if lv, ok := v.(LString); ok {
5050
return string(lv)
51+
} else if LVCanConvToString(v) {
52+
return ls.ToString(n)
5153
}
5254
ls.TypeError(n, LTString)
5355
return ""

auxlib_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ func TestCheckString(t *testing.T) {
4949
L.Push(LString("aaa"))
5050
errorIfNotEqual(t, "aaa", L.CheckString(2))
5151
L.Push(LNumber(10))
52-
L.CheckString(3)
52+
errorIfNotEqual(t, "10", L.CheckString(3))
53+
L.Push(L.NewTable())
54+
L.CheckString(4)
5355
return 0
54-
}, "string expected, got number")
56+
}, "string expected, got table")
5557
}
5658

5759
func TestCheckBool(t *testing.T) {

0 commit comments

Comments
 (0)