Skip to content

Commit

Permalink
Merge pull request #32 from scr-oath/copy-return-err
Browse files Browse the repository at this point in the history
  • Loading branch information
scr-oath authored Aug 8, 2022
2 parents c7fc84f + 8801310 commit 152828b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ioutil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ local input_fh, err = io.open("./test/file.test", "r")
assert(not err, err)
local output_fh, err = io.open("./test/file2.data", "w")
assert(not err, err)
ioutil.copy(output_fh, input_fh)
err = ioutil.copy(output_fh, input_fh)
assert(not err, err)
input_fh:close()
output_fh:close()
```
Expand Down
6 changes: 4 additions & 2 deletions ioutil/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func Copy(L *lua.LState) int {
reader := lio.CheckIOReader(L, 2)
L.Pop(L.GetTop())
if _, err := io.Copy(writer, reader); err != nil {
L.RaiseError(err.Error())
L.Push(lua.LString(err.Error()))
return 1
}
return 0
}
Expand All @@ -51,7 +52,8 @@ func CopyN(L *lua.LState) int {
n := L.CheckInt64(3)
L.Pop(L.GetTop())
if _, err := io.CopyN(writer, reader, n); err != nil {
L.RaiseError(err.Error())
L.Push(lua.LString(err.Error()))
return 1
}
return 0
}

0 comments on commit 152828b

Please sign in to comment.