Wiring and Lua code to read a limit switch

I’m using a Lua script on Pixhawk 6X to control a servo to move some custom hardware. I want to wire up a limit switch to the hardware and read its state from the script, so that it knows when the intended action has been completed.

Q: How (exactly) do I wire up a limit switch to Pixhawk6X and read its state from Lua

Buttons — Copter documentation talks about “switches”, but it looks like they have to be on the RC.
CUAV Pixhawk v6X — Copter documentation tells me there are GPIO but not how to wire or access them in Lua
GPIOs — Copter documentation is very broad an un-specific.