In early 2015 I implemented some LUA scripting primitives in MAME, in order to allow hooking real-time logic to emulation state and drawing overlays like these (Street Fighter 2 hitboxes):
These are some of the enhancements I contributed to the initial LUA engine of MAME to achieve that:
Basic API documentation is available here.