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

Function get_table_str_opt

src/nhlua.c:1054–1076  ·  view source on GitHub ↗

get optional string value from table. return value must be freed by caller. */

Source from the content-addressed store, hash-verified

1052/* get optional string value from table.
1053 return value must be freed by caller. */
1054char *
1055get_table_str_opt(lua_State *L, const char *name, char *defval)
1056{
1057 const char *ret;
1058 int ltyp;
1059
1060 lua_getfield(L, -1, name);
1061 ltyp = lua_type(L, -1);
1062 if (ltyp == LUA_TSTRING || ltyp == LUA_TNIL) {
1063 ret = luaL_optstring(L, -1, defval);
1064 } else if (ltyp == LUA_TFUNCTION) {
1065 nhl_pcall_handle(L, 0, 1, "get_table_str_opt", NHLpa_panic);
1066 ret = luaL_optstring(L, -1, defval);
1067 } else {
1068 nhl_error(L, "get_table_str_opt: no string");
1069 }
1070 if (ret) {
1071 lua_pop(L, 1);
1072 return dupstr(ret);
1073 }
1074 lua_pop(L, 1);
1075 return NULL;
1076}
1077
1078int
1079get_table_boolean(lua_State *L, const char *name)

Callers 15

com_pager_coreFunction · 0.85
get_table_mapchr_optFunction · 0.85
nhl_testFunction · 0.85
init_dungeon_levelsFunction · 0.85
init_dungeon_branchesFunction · 0.85
init_dungeon_dungeonsFunction · 0.85
get_table_monclassFunction · 0.85
get_table_montypeFunction · 0.85
lspo_monsterFunction · 0.85
get_table_objclassFunction · 0.85
get_table_objtypeFunction · 0.85
lspo_objectFunction · 0.85

Calls 3

nhl_pcall_handleFunction · 0.85
nhl_errorFunction · 0.85
dupstrFunction · 0.85

Tested by

no test coverage detected