MCPcopy Create free account
hub / github.com/DFHack/dfhack / get_int_field

Function get_int_field

library/LuaApi.cpp:175–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173
174template<class T>
175static bool get_int_field(lua_State *L, T *pf, int idx, const char *name, int defval)
176{
177 lua_getfield(L, idx, name);
178 bool nil = lua_isnil(L, -1);
179 if (nil) *pf = T(defval);
180 else if (lua_isnumber(L, -1)) *pf = T(lua_tointeger(L, -1));
181 else luaL_error(L, "Field %s is not a number.", name);
182 lua_pop(L, 1);
183 return !nil;
184}
185
186template<class T>
187static bool get_int_or_closure_field(lua_State *L, T *pf, int idx, const char *name, int defval)

Callers 2

get_char_fieldFunction · 0.70
decode_penFunction · 0.70

Calls 3

lua_getfieldFunction · 0.85
lua_isnumberFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected