Author Topic: Generate Type definitions for FSO API  (Read 338 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
Generate Type definitions for FSO API
Over the past few months I have been working on improving the quality of the documentation FSO automatically generates for the scripting API. The most important basic feature of that was to add a JSON generator in addition to the existing HTML one for the documentation. This allows to write external tools that take this information and do something useful with it. My use case was to generate type definitions for both Lua and TypeScript.

I wrote a small tool that takes the JSON generated by FSO and writes another file that can be used for getting much better coding assistance when writing scripts for FSO.
This tool is written in TypeScript and is published on npm:
If you install that globally you will get a fso-typings command line tool. The built-in help messages should hopefully be sufficient...

The Lua generator was written specifically for this IntelliJ plugin which I find very useful for writing scripts for FSO:
If you use the typings generator then simply make it generate the type information to "data/api/fso.lua" and the plugin will pick up the definitions and offer you code completion for most API functions.

Wait, why TypeScript?
Because of this:
That is a compiler that translates TypeScript to Lua which was the original reason I built the JSON support but never got around to actually using it "in production".

That is all,
Have a nice day :p


Offline wookieejedi

  • 29
  • Intensify Forward Firepower
Re: Generate Type definitions for FSO API
Awesome, thanks for the formal writeup and info. This tool is highly useful.