MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / pushJsonNumber

Function pushJsonNumber

app/src/DataModel/Scripting/ScriptApiCall.cpp:335–349  ·  view source on GitHub ↗

* @brief Pushes a JSON double, narrowing to lua_Integer only when finite, in the qint64 range, * and exact; the range check must precede the cast, which is UB otherwise. */

Source from the content-addressed store, hash-verified

333 * and exact; the range check must precede the cast, which is UB otherwise.
334 */
335static void pushJsonNumber(lua_State* L, double d)
336{
337 constexpr double kInt64Min = -9223372036854775808.0;
338 constexpr double kInt64Max = 9223372036854775808.0;
339
340 if (std::isfinite(d) && d >= kInt64Min && d < kInt64Max) {
341 const qint64 i = static_cast<qint64>(d);
342 if (static_cast<double>(i) == d) {
343 lua_pushinteger(L, static_cast<lua_Integer>(i));
344 return;
345 }
346 }
347
348 lua_pushnumber(L, d);
349}
350
351/**
352 * @brief Pushes a QJsonObject onto the Lua stack as a string-keyed table.

Callers 1

jsonValueToLuaFunction · 0.85

Calls 3

isfiniteFunction · 0.85
lua_pushintegerFunction · 0.85
lua_pushnumberFunction · 0.85

Tested by

no test coverage detected