MCPcopy Create free account
hub / github.com/NetHack/NetHack / get_table_int_or_random

Function get_table_int_or_random

src/sp_lev.c:3406–3437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3404/* the hash key 'name' is an integer or "random",
3405 or if not existent, also return rndval */
3406staticfn lua_Integer
3407get_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
3439RESTORE_WARNING_UNREACHABLE_CODE
3440

Callers 1

lspo_objectFunction · 0.85

Calls 2

eosFunction · 0.85
nhl_errorFunction · 0.85

Tested by

no test coverage detected