For anyone not aware, there is a very convenient way to set up VS Code for Lua autocompletion, including all ArduPilot bindings. It’s not really new and has been mentioned in several forum topics and video presentations.
- Install VS Code
- Install the Lua extension from within VS Code’s extension manager
- Drop a copy of
AP_Scripting/docs/docs.luainto your working directory
A word of caution, though (I just discovered this). If you have multiple scripts in the same directory and use the refactor (F2) feature of VS Code on any global variable or function name (anything in the main code block not prefaced with
local), it will refactor that name across all files in the directory.
Remember, Lua (outside of ArduPilot) allows for importing modules just like Python, and VS Code isn’t “smart” enough to recognize that globally scoped structures cannot reference one another in ArduPilot’s “sandboxed” script engine approach.
So, that’s yet another reason to use the
local keyword for all declarations. There is one exception. Any callback function (as in,
update(), where you intend to schedule it with a call like
return update, 200) should not be declared as