Skip to content

Commit 1c95ca9

Browse files
Make low level table sets error out on nil key, and change API test to expect same. Fixes #20
1 parent e78c845 commit 1c95ca9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

api_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ func TestTable(t *testing.T) {
213213
assert(t, l.AbsIndex(-1) == 0, "Items remain on stack after all values popped.")
214214

215215
// Make sure nil is not a valid key
216-
assert(t, !f(nil), "Nil acting as valid key.")
216+
err := l.Protect(func() {
217+
f2(nil, nil)
218+
})
219+
if err == nil {
220+
t.Error("Setting nil key does not raise error.")
221+
}
217222

218223
// And finally do some equivalent key tests
219224
assert(t, f2(1, 1.0), "Equivalent keys failing. (1, 1.0)")

table.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ package lua
2929
import "math"
3030
import "runtime"
3131

32+
import "github.com/milochristiansen/lua/luautil"
33+
3234
// Set to 0 for zero based table indexing. This is only partly tested!
3335
var TableIndexOffset = 1
3436

@@ -239,7 +241,7 @@ func (tbl *table) existsInt(k int64) bool {
239241
func (tbl *table) SetRaw(k, v value) {
240242
switch idx := k.(type) {
241243
case nil:
242-
return
244+
luautil.Raise("Cannot set nil table index.", luautil.ErrTypGenRuntime)
243245
case float64:
244246
if math.IsNaN(idx) {
245247
return

0 commit comments

Comments
 (0)