Here is a solution! (Well, part of it) Lua Scripts not working on Pixhawk 4 - #12 by Christopher_Milner
The full solution is quite cursed. There are two things at play: For the Pixhawk 4, you need less than is allocated by default in SCR_HEAP_SIZE but more than some other value. I literally trial and error’d my way to a SCR_HEAP_SIZE that wouldn’t throw a PreArm fail. For me that number was 83968. Which is like, random. Cursed. Anyway hope this helps somebody.