sol2
sol2 copied to clipboard
SOL_SAFE_NUMERICS and SOL_NO_CHECK_NUMBER_PRECISION
Hi,
Basically I would like to be able to use the right overload when it exists but if there is no overload then that it default to classic cast of float to int.
Is that possible ?
Thanks !
Write a function that takes double to capture all Lua numbers, and then cast + call your desired int-based function. There's no functionality to do this on a per-function level, but maybe I should add a cast_policy or figure out something similar...
ok so basically I remove SOL_NO_CHECK_NUMBER_PRECISION and only keep SOL_SAFE_NUMERICS and handle manually the float to int overload. But yeah something built-in would be great :)
Basically I want something like in c++ Where it first look for the best candidate and then cast if necessary
C++-style overloading is one of the most expensive kinds of overloading there is. "Best candidate" means I can't stop early when searching.
Most of the time there are few overload though no ? and maybe this should be opt in so you know what are the tradeoff
"Best match" overloading has been a thing I've been thinking about for a long time.
I should probably give it a shot here, conversions allowed and all.
Slight out-loud think:
sol::overload_best_loose( f0, f1, f2, ... );Allows conversions, needs a better namesol::overload_best_strict( f0, f1, f2, ... );Disallows conversionssol::overload_best( f0, f1, f2, ... );Disallows conversions (or maybe allows? We have both there, so picking a default behavior either way is okay and honestly is probably "whatever one is less effort" first)
I wonder if this should be on a per function basis or just global like you did with SOL_SAFE_NUMERICS and SOL_NO_CHECK_NUMBER_PRECISION. In any case, both would suit me.
If you want to do it c++ style, the default could be to always allow all conversion (given a global define) and if you want you can force it to be strict on a per function basis (c++ explicit)
Yeah, that is planned, but I still need a basic default for it. Like SOL_SAFE_OVERLOAD_BEST or something, where it defaults to being strict...
Any progress on this ? :)
Not something I can check in! Because, as it turns out, "best candidate" is obscenely hard and there's a reason why every single compiler engineer in the world hates C++-style overload resolution. :D