7 Commits

Author SHA1 Message Date
Thomas Watson
7e777b6371 AP_Scripting: fix CRSF leaks and nullptr dereferences
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.
2026-01-07 08:56:01 -06:00
Thomas Watson
a550087eee AP_Scripting: generator: dynamically create userdata metatables
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.
2025-12-16 11:13:16 +11:00
Andy Piper
94bc8d86e3 AP_Scripting: add CRSF peek_menu_event() and pop_menu_event()
add CRSF send_response() method
2025-11-19 19:01:11 +11:00
Andy Piper
043054306b AP_Scripting: add CRSF docs and lua wrapper fixes 2025-04-09 17:16:58 +10:00
Andy Piper
a62207298e AP_Scripting: rename AP_CRSF_SCRIPTING_ENABLED 2025-04-09 17:16:58 +10:00
Andy Piper
25f0b7bda5 AP_Scripting: protect CRSF scripting when there is no scripting 2025-04-09 17:16:58 +10:00
Andy Piper
fa36e5623d AP_Scripting: add CRSF menu bindings
add CRSF menu example
add scripted CRSF menu events
custom CRSFMenu helpers
play Beethoven's 5th on CRSF command
use native packed strings for CRSF menus and payloads
support CRSF submenus
2025-04-09 17:16:58 +10:00