Skip to content

Commit f7b5058

Browse files
authored
Merge pull request #186 from alicebob/uplua
update lua depencency
2 parents 18ea696 + a3fe290 commit f7b5058

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

cmd_scripting_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,22 +432,22 @@ func TestCmdEvalReply(t *testing.T) {
432432

433433
mustContain(t, c,
434434
"EVAL", `return redis.error_reply()`, "0",
435-
"string expected, got nil",
435+
"wrong number or type of arguments",
436436
)
437437

438438
mustContain(t, c,
439439
"EVAL", `return redis.error_reply(1)`, "0",
440-
"string expected, got number",
440+
"wrong number or type of arguments",
441441
)
442442

443443
mustContain(t, c,
444444
"EVAL", `return redis.status_reply()`, "0",
445-
"string expected, got nil",
445+
"wrong number or type of arguments",
446446
)
447447

448448
mustContain(t, c,
449449
"EVAL", `return redis.status_reply(1)`, "0",
450-
"string expected, got number",
450+
"wrong number or type of arguments",
451451
)
452452
}
453453

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/alicebob/miniredis/v2
22

33
require (
44
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a
5-
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
5+
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da
66
)
77

88
go 1.13

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
55
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
66
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
77
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
8+
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
9+
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
810
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

integration/script_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ func TestLua(t *testing.T) {
119119
c.Do("EVAL", "return {ok = 'great', notok = 'yes'}", "0") // doc error?
120120
c.Do("EVAL", "return {1, 2, ok = 'great', notok = 'yes'}", "0") // doc error?
121121

122-
c.DoLoosely("EVAL", "return redis.error_reply(1)", "0")
123-
c.DoLoosely("EVAL", "return redis.error_reply()", "0")
124-
c.DoLoosely("EVAL", "return redis.error_reply(redis.error_reply('foo'))", "0")
125-
c.DoLoosely("EVAL", "return redis.status_reply(1)", "0")
126-
c.DoLoosely("EVAL", "return redis.status_reply()", "0")
127-
c.DoLoosely("EVAL", "return redis.status_reply(redis.status_reply('foo'))", "0")
122+
c.Error("type of arguments", "EVAL", "return redis.error_reply(1)", "0")
123+
c.Error("type of arguments", "EVAL", "return redis.error_reply()", "0")
124+
c.Error("type of arguments", "EVAL", "return redis.error_reply(redis.error_reply('foo'))", "0")
125+
c.Error("type of arguments", "EVAL", "return redis.status_reply(1)", "0")
126+
c.Error("type of arguments", "EVAL", "return redis.status_reply()", "0")
127+
c.Error("type of arguments", "EVAL", "return redis.status_reply(redis.status_reply('foo'))", "0")
128128
})
129129

130130
// state inside lua

lua.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,24 @@ func mkLuaFuncs(srv *server.Server, c *server.Peer) map[string]lua.LGFunction {
9595
"call": mkCall(true),
9696
"pcall": mkCall(false),
9797
"error_reply": func(l *lua.LState) int {
98-
msg := l.CheckString(1)
98+
v := l.Get(1)
99+
msg, ok := v.(lua.LString)
100+
if !ok {
101+
l.Error(lua.LString("wrong number or type of arguments"), 1)
102+
return 0
103+
}
99104
res := &lua.LTable{}
100105
res.RawSetString("err", lua.LString(msg))
101106
l.Push(res)
102107
return 1
103108
},
104109
"status_reply": func(l *lua.LState) int {
105-
msg := l.CheckString(1)
110+
v := l.Get(1)
111+
msg, ok := v.(lua.LString)
112+
if !ok {
113+
l.Error(lua.LString("wrong number or type of arguments"), 1)
114+
return 0
115+
}
106116
res := &lua.LTable{}
107117
res.RawSetString("ok", lua.LString(msg))
108118
l.Push(res)

0 commit comments

Comments
 (0)