| 3404 | /* the hash key 'name' is an integer or "random", |
| 3405 | or if not existent, also return rndval */ |
| 3406 | staticfn lua_Integer |
| 3407 | get_table_int_or_random(lua_State *L, const char *name, int rndval) |
| 3408 | { |
| 3409 | lua_Integer ret; |
| 3410 | char buf[BUFSZ]; |
| 3411 | |
| 3412 | lua_getfield(L, 1, name); |
| 3413 | if (lua_type(L, -1) == LUA_TNIL) { |
| 3414 | lua_pop(L, 1); |
| 3415 | return rndval; |
| 3416 | } |
| 3417 | if (!lua_isnumber(L, -1)) { |
| 3418 | const char *tmp = lua_tostring(L, -1); |
| 3419 | |
| 3420 | if (tmp && !strcmpi("random", tmp)) { |
| 3421 | lua_pop(L, 1); |
| 3422 | return rndval; |
| 3423 | } |
| 3424 | Sprintf(buf, "Expected integer or \"random\" for \"%s\", got ", name); |
| 3425 | if (tmp) |
| 3426 | Sprintf(eos(buf), "\"%s\"", tmp); |
| 3427 | else |
| 3428 | Strcat(buf, "<Null>"); |
| 3429 | nhl_error(L, buf); |
| 3430 | /*NOTREACHED*/ |
| 3431 | lua_pop(L, 1); |
| 3432 | return 0; |
| 3433 | } |
| 3434 | ret = luaL_optinteger(L, -1, rndval); |
| 3435 | lua_pop(L, 1); |
| 3436 | return ret; |
| 3437 | } |
| 3438 | |
| 3439 | RESTORE_WARNING_UNREACHABLE_CODE |
| 3440 |
no test coverage detected