| 5316 | } |
| 5317 | |
| 5318 | boolean |
| 5319 | get_coord(lua_State *L, int i, lua_Integer *x, lua_Integer *y) |
| 5320 | { |
| 5321 | boolean ret = FALSE; |
| 5322 | int ltyp = lua_type(L, i); |
| 5323 | |
| 5324 | if (ltyp == LUA_TTABLE) { |
| 5325 | int arrlen; |
| 5326 | boolean gotx = FALSE; |
| 5327 | |
| 5328 | lua_getfield(L, i, "x"); |
| 5329 | if (!lua_isnil(L, -1)) { |
| 5330 | *x = luaL_checkinteger(L, -1); |
| 5331 | gotx = TRUE; |
| 5332 | } |
| 5333 | lua_pop(L, 1); |
| 5334 | |
| 5335 | if (gotx) { |
| 5336 | lua_getfield(L, i, "y"); |
| 5337 | if (!lua_isnil(L, -1)) { |
| 5338 | *y = luaL_checkinteger(L, -1); |
| 5339 | lua_pop(L, 1); |
| 5340 | ret = TRUE; |
| 5341 | } else { |
| 5342 | nhl_error(L, "Not a coordinate"); |
| 5343 | /*NOTREACHED*/ |
| 5344 | return FALSE; |
| 5345 | } |
| 5346 | } else { |
| 5347 | lua_len(L, i); |
| 5348 | arrlen = lua_tointeger(L, -1); |
| 5349 | lua_pop(L, 1); |
| 5350 | if (arrlen != 2) { |
| 5351 | nhl_error(L, "Not a coordinate"); |
| 5352 | /*NOTREACHED*/ |
| 5353 | return FALSE; |
| 5354 | } |
| 5355 | |
| 5356 | *x = get_table_intarray_entry(L, i, 1); |
| 5357 | *y = get_table_intarray_entry(L, i, 2); |
| 5358 | |
| 5359 | return TRUE; |
| 5360 | } |
| 5361 | } else if (ltyp != LUA_TNIL) { |
| 5362 | /* non-existent coord is ok */ |
| 5363 | nhl_error(L, "non-table coord specified"); |
| 5364 | } |
| 5365 | return ret; |
| 5366 | } |
| 5367 | |
| 5368 | RESTORE_WARNING_UNREACHABLE_CODE |
| 5369 |
no test coverage detected