I need 3 different failsafe functions depending on the position of my 3 position stick on my rc. Is that possible?
Maybe I can create a custom lua sciprt and launch it with a chosen rc channel
Yup custom Lua script is the way you would do this.
The main issue: how to run a lua scipt on the board with 1mb flash and maybe some external flash, so that scr_enable will be present with f405 wing
It is unlikely to work well, AFAIK you would have to remove pretty much everything else to fit scripting and it would still have quite limited space for scripts.
The easiest way would be to get H7 based flight controller like Matek H743 WING, the other option is to write the code in C++.
In that case the easiest way would be to port UserCode from ArduCopter, it should be fairly easy to do, will make keeping your fork up to date easier (code that has to be added will be in rarely modified places).
An alternative more “proper” way would be to implement a new AUX function to select failsafe behavior. Though as it will be directly affecting failsafe code you will have to be even more careful.