Adap the "Remove unnecessary float limits from script API" to checks of floats

* backport 8ff3fadba0
* issues related:
    * https://github.com/minetest/minetest/issues/11742
    * https://github.com/minetest/minetest/issues/6129
* really close #4
* TODO adapt to use FLOAT checks
This commit is contained in:
mckaygerhard 2022-07-20 21:55:33 +02:00
parent b08d3334a2
commit 06ea7329de

View File

@ -28,7 +28,7 @@ extern "C" {
#include "common/c_converter.h"
#include "common/c_internal.h"
#include "constants.h"
#include <cmath>
#define CHECK_TYPE(index, name, type) { \
int t = lua_type(L, (index)); \
@ -41,8 +41,8 @@ extern "C" {
}
#define CHECK_POS_COORD(name) CHECK_TYPE(-1, "position coordinate '" name "'", LUA_TNUMBER)
#define CHECK_FLOAT_RANGE(value, name) \
if (value < F1000_MIN || value > F1000_MAX) { \
warningstream << "Invalid float vector dimension range '" name "' " << \
if (value < F1000_MIN || value > F1000_MAX || std::isnan(value) || std::isinf(value) ) { \
warningstream << "Invalid float vector dimension range or null value given '" name "' " << \
"(expected " << F1000_MIN << " < " name " < " << F1000_MAX << \
" got " << value << "). restarted to max / min" << std::endl; \
if (value < F1000_MIN) \
@ -166,10 +166,12 @@ v2f check_v2f(lua_State *L, int index)
lua_getfield(L, index, "x");
CHECK_POS_COORD("x");
p.X = lua_tonumber(L, -1);
CHECK_FLOAT_RANGE(p.X, "x")
lua_pop(L, 1);
lua_getfield(L, index, "y");
CHECK_POS_COORD("y");
p.Y = lua_tonumber(L, -1);
CHECK_FLOAT_RANGE(p.Y, "x")
lua_pop(L, 1);
return p;
}