MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_integer_option

Function json_integer_option

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:220–239  ·  view source on GitHub ↗

Process integer options for configuration functions */

Source from the content-addressed store, hash-verified

218
219/* Process integer options for configuration functions */
220static int json_integer_option(lua_State *l, int optindex, int *setting,
221 int min, int max)
222{
223 char errmsg[64];
224 int value;
225
226 if (!lua_isnil(l, optindex)) {
227 int result;
228 value = luaL_checkinteger(l, optindex);
229 result = _snprintf(errmsg, sizeof(errmsg), "expected integer between %d and %d", min, max);
230 if (result == sizeof(errmsg) || result < 0)
231 errmsg[sizeof(errmsg) - 1] = '\0';
232 luaL_argcheck(l, min <= value && value <= max, 1, errmsg);
233 *setting = value;
234 }
235
236 lua_pushinteger(l, *setting);
237
238 return 1;
239}
240
241/* Process enumerated arguments for a configuration function */
242static int json_enum_option(lua_State *l, int optindex, int *setting,

Calls

no outgoing calls

Tested by

no test coverage detected