Tangent128 / luasdl2

A pure C binding of SDL 2.0 for Lua 5.1, Lua 5.2, and LuaJIT.
ISC License
385 stars 74 forks source link

Provide LSP-friendly documentation file #94

Open proskur1n opened 2 years ago

proskur1n commented 2 years ago

Hello, at the moment your language server won't give you helpful diagnostics and autocompletions because luasdl2 is a simple dynamic library that doesn't know anything about C comments. sumneko/lua-language-server has the concept of "libraries" to provide autocomplete and documentation for native C bindings.

Below is a tiny sample that documents SDL.init. I propose to provide such definitions for everything inside luasdl2. The only problem is that somebody would need to redo all the comments inside C source files to include type information for parameter and return values.

---@meta
local SDL = {}

---@enum SDL.flags
SDL.flags = {
    Audio = 16,
    Events = 16384,
    Everything = 62001,
    GameController = 8192,
    Haptic = 4096,
    Joystick = 512,
    NoParachute = 1048576,
    Video = 32,
}

---@param flags SDL.flags[]
---@return boolean # True on success or false
---@return string  # The error message
function SDL.init(flags) end

return SDL