Skip to content

Commit

Permalink
update lua depencency
Browse files Browse the repository at this point in the history
And deal with a more permissive `CheckString()` function: yuin/gopher-lua@a519e4d
  • Loading branch information
alicebob committed Jan 13, 2021
1 parent 18ea696 commit a3fe290
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cmd_scripting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,22 +432,22 @@ func TestCmdEvalReply(t *testing.T) {

mustContain(t, c,
"EVAL", `return redis.error_reply()`, "0",
"string expected, got nil",
"wrong number or type of arguments",
)

mustContain(t, c,
"EVAL", `return redis.error_reply(1)`, "0",
"string expected, got number",
"wrong number or type of arguments",
)

mustContain(t, c,
"EVAL", `return redis.status_reply()`, "0",
"string expected, got nil",
"wrong number or type of arguments",
)

mustContain(t, c,
"EVAL", `return redis.status_reply(1)`, "0",
"string expected, got number",
"wrong number or type of arguments",
)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/alicebob/miniredis/v2

require (
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da
)

go 1.13
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
12 changes: 6 additions & 6 deletions integration/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ func TestLua(t *testing.T) {
c.Do("EVAL", "return {ok = 'great', notok = 'yes'}", "0") // doc error?
c.Do("EVAL", "return {1, 2, ok = 'great', notok = 'yes'}", "0") // doc error?

c.DoLoosely("EVAL", "return redis.error_reply(1)", "0")
c.DoLoosely("EVAL", "return redis.error_reply()", "0")
c.DoLoosely("EVAL", "return redis.error_reply(redis.error_reply('foo'))", "0")
c.DoLoosely("EVAL", "return redis.status_reply(1)", "0")
c.DoLoosely("EVAL", "return redis.status_reply()", "0")
c.DoLoosely("EVAL", "return redis.status_reply(redis.status_reply('foo'))", "0")
c.Error("type of arguments", "EVAL", "return redis.error_reply(1)", "0")
c.Error("type of arguments", "EVAL", "return redis.error_reply()", "0")
c.Error("type of arguments", "EVAL", "return redis.error_reply(redis.error_reply('foo'))", "0")
c.Error("type of arguments", "EVAL", "return redis.status_reply(1)", "0")
c.Error("type of arguments", "EVAL", "return redis.status_reply()", "0")
c.Error("type of arguments", "EVAL", "return redis.status_reply(redis.status_reply('foo'))", "0")
})

// state inside lua
Expand Down
14 changes: 12 additions & 2 deletions lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,24 @@ func mkLuaFuncs(srv *server.Server, c *server.Peer) map[string]lua.LGFunction {
"call": mkCall(true),
"pcall": mkCall(false),
"error_reply": func(l *lua.LState) int {
msg := l.CheckString(1)
v := l.Get(1)
msg, ok := v.(lua.LString)
if !ok {
l.Error(lua.LString("wrong number or type of arguments"), 1)
return 0
}
res := &lua.LTable{}
res.RawSetString("err", lua.LString(msg))
l.Push(res)
return 1
},
"status_reply": func(l *lua.LState) int {
msg := l.CheckString(1)
v := l.Get(1)
msg, ok := v.(lua.LString)
if !ok {
l.Error(lua.LString("wrong number or type of arguments"), 1)
return 0
}
res := &lua.LTable{}
res.RawSetString("ok", lua.LString(msg))
l.Push(res)
Expand Down

0 comments on commit a3fe290

Please sign in to comment.