Listening for MAVLink messages in Lua scripts

I am playing with Lua scripts and managed to create a script which will cause the copter to perform a 360 degree yaw when triggered. At the moment its triggered by listening to the camera servo function which works fine (in SITL).

But I was hoping to be able to trigger it based on a MAVLink message. Maybe by sending a NAMED_VALUE_INT message from the GCS to the autopilot and having the script listen out for this specific named message and then acting on it. The named message could then not only cause the trigger but also indicate additional information like yawing in CW or CCW directions and things like that.

Using gcs:send_text() I can sent status messages to the GCS but could not yet find a way to receive or listen for messages. I have also looked through bindings.desc but don’t see anything useful there. Does anyone know if it is possible and how to do this (hopefully without having to compile a custom firmware version)?

You can’t poll MAVLINK messages, but you should look into scripted aerobatics and the NAV_SCRIPT_TIME command.