If I understand correctly, you should be able to do this more straightforwardly with
if grid.value[idx] # ... end
Indexing a table with a number fetches the corresponding row of the table as a dictionary, which will be "truthy" so long as the table has at least one column. If the row does not exist, indexing in this manner will result in nil, which is a "falsey" value:
t:insert a b with 11 22 33 44 55 66 end
# +----+----+
# | a | b |
# +----+----+
# | 11 | 22 |
# | 33 | 44 |
# | 55 | 66 |
# +----+----+
t[2]
# {"a":55,"b":66}
t[-1]~nil
# 1
t[3]~nil
# 1
Another approach would be to use the "count" operator to determine the number of rows in the table, and compare that to "idx":
count t # 3
Does that help at all?