parent
9c7766835b
commit
dc7fe111bf
|
@ -476,4 +476,47 @@ void testLuaExecString(const char* script) {
|
||||||
|
|
||||||
#endif // EFI_UNIT_TEST
|
#endif // EFI_UNIT_TEST
|
||||||
|
|
||||||
|
// This is technically non-compliant, but it's only used for lua float parsing.
|
||||||
|
// It doesn't properly handle very small and very large numbers, and doesn't
|
||||||
|
// parse numbers in the format 1.3e5 at all.
|
||||||
|
extern "C" float strtof_rusefi(const char* str, char** endPtr) {
|
||||||
|
bool afterDecimalPoint = false;
|
||||||
|
float div = 1; // Divider to place digits after the decimal point
|
||||||
|
|
||||||
|
if (endPtr) {
|
||||||
|
*endPtr = const_cast<char*>(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
float integerPart = 0;
|
||||||
|
float fractionalPart = 0;
|
||||||
|
|
||||||
|
while (*str != '\0') {
|
||||||
|
char c = *str;
|
||||||
|
int digitVal = c - '0';
|
||||||
|
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
if (!afterDecimalPoint) {
|
||||||
|
// Integer part
|
||||||
|
integerPart = 10 * integerPart + digitVal;
|
||||||
|
} else {
|
||||||
|
// Fractional part
|
||||||
|
fractionalPart = 10 * fractionalPart + digitVal;
|
||||||
|
div *= 10;
|
||||||
|
}
|
||||||
|
} else if (c == '.') {
|
||||||
|
afterDecimalPoint = true;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
str++;
|
||||||
|
|
||||||
|
if (endPtr) {
|
||||||
|
*endPtr = const_cast<char*>(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return integerPart + fractionalPart / div;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EFI_LUA
|
#endif // EFI_LUA
|
||||||
|
|
|
@ -309,7 +309,10 @@
|
||||||
|
|
||||||
#define l_mathop(op) op##f
|
#define l_mathop(op) op##f
|
||||||
|
|
||||||
#define lua_str2number(s,p) strtof((s), (p))
|
// defined in Lua.cpp
|
||||||
|
float strtof_rusefi(const char*, char**);
|
||||||
|
|
||||||
|
#define lua_str2number(s,p) strtof_rusefi((s), (p))
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue