sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

how to convert `std::optional` to `sol::optional`?

Open scarf005 opened this issue 4 months ago • 1 comments

pretty certain there's easier way to do this but i can't seem to find any info on neither docs nor github issues

        std::optional<tripoint> stdOpt = choose_adjacent( message, allow_vertical.value_or( false ) );
        if( stdOpt.has_value() )
        {
            return sol::optional<tripoint>( *stdOpt );
        }
        return sol::optional<tripoint>();

scarf005 avatar Aug 08 '25 13:08 scarf005

Concise code would be:

auto solOpt = (stdOpt ? sol::optional<tripoint>(*stdOpt) : sol::nullopt);

🧟

EvanBalster avatar Nov 24 '25 00:11 EvanBalster