AP_Scripting: allow logging lua boolean with uint8 format `B`

This commit is contained in:
Iampete1 2024-06-17 21:54:20 +01:00 committed by Andrew Tridgell
parent 32750476be
commit cc99ebf872
1 changed files with 10 additions and 4 deletions

View File

@ -459,11 +459,17 @@ int AP_Logger_Write(lua_State *L) {
case 'M': // uint8_t (flight mode) case 'M': // uint8_t (flight mode)
case 'B': { // uint8_t case 'B': { // uint8_t
int isnum; int isnum;
const lua_Integer tmp1 = lua_tointegerx(L, arg_index, &isnum); lua_Integer tmp1 = lua_tointegerx(L, arg_index, &isnum);
if (!isnum || (tmp1 < 0) || (tmp1 > UINT8_MAX)) { if (!isnum || (tmp1 < 0) || (tmp1 > UINT8_MAX)) {
luaM_free(L, buffer); // Also allow boolean
luaL_argerror(L, arg_index, "argument out of range"); if (!isnum && lua_isboolean(L, arg_index)) {
// no return tmp1 = lua_toboolean(L, arg_index);
} else {
luaM_free(L, buffer);
luaL_argerror(L, arg_index, "argument out of range");
// no return
}
} }
uint8_t tmp = static_cast<uint8_t>(tmp1); uint8_t tmp = static_cast<uint8_t>(tmp1);
memcpy(&buffer[offset], &tmp, sizeof(uint8_t)); memcpy(&buffer[offset], &tmp, sizeof(uint8_t));