Skip to content

Stack<float> rejects NaN and Inf values, preventing proper error handling in application logic #202

@owch

Description

@owch

[[nodiscard]] static Result push(lua_State* L, float value)
{
#if LUABRIDGE_SAFE_STACK_CHECKS
if (! lua_checkstack(L, 1))
return makeErrorCode(ErrorCode::LuaStackOverflow);
#endif
if (! is_floating_point_representable_by(value))
return makeErrorCode(ErrorCode::FloatingPointDoesntFitIntoLuaNumber);
lua_pushnumber(L, static_cast<lua_Number>(value));
return {};
}

Currently, Stack<float>::push() rejects NaN and Inf values with FloatingPointDoesntFitIntoLuaNumber error before they can reach Lua. This prevents applications from handling these special floating-point values in the application logic.

Since Lua supports NaN/Inf, should we allow NaN and Inf values to pass through to Lua where they can be properly handled by application logic?

// In Stack<float>::push()
if (std::isnan(value) || std::isinf(value)) {
    lua_pushnumber(L, static_cast<lua_Number>(value));
    return {};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions