Hi Everyone,
I got the API list from Lua Glider IDE, it downloads the raw corona .lua files for its own autocomplete.
This seems to be a common misconception about our autocomplete stubs. We actually went through the docs ourselves and created these lua files. In no way did we download any corona source! We would appreciate if you asked us before porting over our hard work to another IDE. The point of doing it this way as opposed to putting into a database or xml file is that we can use the same scanning engine for both autocomplete stubs and your own code. All the luadoc comments you see you can use for your own code and get the same type aware autocompletion you see for the Corona API. Also, it allows for some very powerful stuff. Like for instance:
--- @DeepInspect -- @param object @class DisplayObject -- @param bodyType @optional @class string @enum "static", "dynamic","kinematic" -- @param optionsTable -- @return -- function physics.addBody(object, bodyType, optionsTable ) object = Body end
what the code snippet does is attaches a Body class to the first parameter.The addBody function transformed the object parameter into a physics body object. Rather than using some obscure xml format to describe this behavior, we just use a simple lua function.
The result can be seen with the autocomplete:
btw “Body” is just a lua table that looks like this:
---@extends DisplayObject local Body = {} Body.angularDamping = 1 Body.angularVelocity = 1 ---@enum "static", "dynamic", "kinematic" Body.BodyType ="" Body.isAwake = true Body.isBodyActive = true Body.isBullet = true Body.isFixedRotation = true Body.isSensor = true Body.isSleepingAllowed = true Body.linearDamping = 1
What is the purpose of the DeepInspect directive? When Glider inspects a lua function (either the stubs or your own functions) it “runs” the function in our homemade Lua virtual machine that analyzes the function to figure out a few things:
- What are the parameters? What types are they? How many are there?
- What is returned? How many returns? What are the types of those returns?
- Where is this symbol being used? Has it been used before? Is this a declaration?
All this information is extracted automatically from parsing and analyzing lua source code. The Luadocs just help out the analyzer but they are not strictly required. For most functions, the first inspection result can be cached and reused, but there are a few functions with side effects that must be “re-run” every time. This is what the @DeepInspect directive does.
Take for instance:
Glider can figure out all this so you don’t have to remember it or refer back and forth to documentation yourself.
And best of all you don’t need to learn any xml formats, its all just plain Lua code. And you can create your own stubs for your project, just create skeleton functions and the autocomplete entries will show up for you and the rest of your team.
We are going to open source our stubs and the Glider Corona Plugin. We need help updating the stubs to make the smartest autocomplete you have ever seen for lua. Please let us know if you are interested in contributing, we will create detailed documentation for how to create effective autocomplete stubs.
Regards,
M.Y. Developers