vallode / dfhack-lua-definitions

LuaLS lua language server definitions for DFHack's library
4 stars 0 forks source link

Expose DFHack C++ modules #4

Open vallode opened 5 months ago

vallode commented 5 months ago

Placeholder issue to gather my thoughts on how we should go about exposing the C++ modules to Lua language server.

vallode commented 5 months ago

Some basic generation is taking place already, mostly via searching the LuaApi.cpp file in dfhack and parsing basic function signatures. This covers a lot of ground but misses some more abstract lua state manipulation functions that would at least be nice to expose a return type of.

vallode commented 4 months ago

On the DFHack Discord there was some discussion about adding type comments (akin to JSDoc) to the relevant cpp files and read that in the type generation. The example Thyrus was quite neat, slightly modifying it gives an example of a c++ function like so:

/*lua
@param base dfhack.pen|dfhack.color
@param pen_or_fg? dfhack.pen|dfhack.color
@param bg? dfhack.color
@param bold? boolean
@return dfhack.pen
*/
static int dfhack_pen_parse(lua_State *L) {}

We can do some simple sanity checking for this (correct @ tag, non reserved name, maybe even checking if the type exists) and output that to the relevant files instead.