If `writechar` failed because the serial buffer was full, then `tx_buf`
could be nil and appending to it would fail. Fix by letting
`writestring` handle the work in this rare case.
Also bump the version to signify the fix.
There are several bogus error messages and checks that are removed.
This should probably be refactored to use ap_objects and avoid
reallocation of the underlying bits.
Fixes:
../../libraries/AP_Scripting/lua_bindings.cpp: In function 'int lua_AP_Vehicle_set_target_velocity_NED(lua_State*)':
../../libraries/AP_Scripting/lua_bindings.cpp:1240:23: error: 'check_AP_Vehicle' was not declared in this scope; did you mean 'check_AC_Fence'?
1240 | AP_Vehicle * ud = check_AP_Vehicle(L);
| ^~~~~~~~~~~~~~~~
| check_AC_Fence
compilation terminated due to -Wfatal-errors.
docs for set_target_velocity_NED()
add set_target_angle_and_rate_and_throttle() for precise vehicle control
manual binding for set_target_velocity_NED() to allow optional boolean
update docs for attitude control
Now that startup RAM usage is not dependent on the number of bindings,
there is little need to specifically measure that phase. This combines
~700 bytes used by the string setup into the initial state usage. But
that number should very rarely change.
The `luaL_testudata` and `luaL_checkudata` functions correctly treat the
absence of a metatable for the type to check as the type not matching,
so there is no need to have the type's metatable in memory until an
object using it exists. Therefore we can defer the metatable's creation
until the first time an object of that type is created.
Saves some 4500 bytes of Lua heap RAM, at least if no such objects are
created. The created metatables are shared between all scripts, so there
is no increase in the total RAM usage if all objects are used. However,
there is some increased risk of heap fragmentation and unexpected
out-of-memory errors on rarely used code paths.
It would be nice to construct the object in the new utility function,
but it's not possible in C++ to take the address of a constructor.
Instead passing in a lambda is ugly, hardly any more efficient, and
screws up constructors which take parameters.
Also optimizes by using the generated userdata creators where possible,
and convincing the compiler to omit unnecessary checks.
The `luaL_testudata` and `luaL_checkudata` functions correctly treat the
absence of a metatable for the type to check as the type not matching,
so there is no need to have the type's metatable in memory until an
object using it exists. Therefore we can defer the metatable's creation
until the first time an object of that type is created.
Saves some 1500 bytes of Lua heap RAM, at least if no such objects are
created. The created metatables are shared between all scripts, so there
is no increase in the total RAM usage if all objects are used. However,
there is some increased risk of heap fragmentation and unexpected
out-of-memory errors on rarely used code paths.
malloc is kinda slow and we were failing to free the memory in tandem
with its original allocated size, causing Lua to believe we still had
the bytes allocated. This created misleading stats and unnecessary GC
pressure, but no actual leak.
Fix by using a stack buffer half the buffer size we use in other
functions but still big enough for the maximum possible log message.
Co-authored-by: jschall <mr.challinger@gmail.com>
The different size won't cause the `accept_msg_ids` array to be
reallocated, but it will still be zeroed up to its new size. If that's
bigger than the old one, then the heap gets corrupted, and mayhem and
destruction ensues.
Fix by only initializing the related data immediately on successful
allocation.
Push a dummy element on a dot call to make the stack look like the
generated bindings, which always expect the colon call (that pushes self
as the first argument) and the intended usage pattern.
Folds in `arg_offset = 1`. Note that none of these routines care about
the first argument as they were fine being called without it.