Top-of-stack Lua scalar -> JSON (numbers/bools/strings; else null).
| 160 | |
| 161 | // Top-of-stack Lua scalar -> JSON (numbers/bools/strings; else null). |
| 162 | nlohmann::json luaScalarToJson(lua_State* L, int idx) { |
| 163 | switch (lua_type(L, idx)) { |
| 164 | case LUA_TBOOLEAN: |
| 165 | return static_cast<bool>(lua_toboolean(L, idx)); |
| 166 | case LUA_TNUMBER: |
| 167 | return lua_tonumber(L, idx); |
| 168 | case LUA_TSTRING: |
| 169 | return std::string(lua_tostring(L, idx)); |
| 170 | default: |
| 171 | return nullptr; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // Render a JSON scalar to a short label (the fallback when an enum option omits |
| 176 | // `label`): integers without a trailing ".0", others via dump(). |
no outgoing calls
no test coverage detected