Other Emmylua API Generator

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
Urada
Prole
Posts: 2
Joined: Sat Oct 09, 2021 1:16 pm

Other Emmylua API Generator

Post by Urada »

I found that there are some problems with an existing emmylua-api generator, and I can't generate a new version of love2d api. For the purpose of practice, I took a little time to rewrite one.
Then the maintainer of emmylua told me that someone has actually fixed the generator, and the latest version of the api has been generated and integrated into sumneko-lua.
Well, I don't want this generator to be thrown in the trash, so I'm posting it here in case someone needs to generate the api file themselves.
This generator generates the sumneko-lua version of emmylua type-hinted annotations (now called luacats).

How to use?
Basically the same as the original generator usage
Download a love2d-api repository to the local, put this file in the folder, create a new api folder, and then use luajit to execute the script

Warn:
This script has only been lightly tested, if you find any problems, feel free to let me know.
Many details are not handled very well, for example, too long instructions may be truncated. Because I was told that this generator has been fixed when the script is about to be completed, I can directly use the new version of love2d api in sumneko-lua
I barely speak English, the damn identifiers are all made up, and I don't know if anyone in an English-speaking country can understand the source code.

If you don't know what emmylua and sumneko-lua are:
Both emmylua and sumneko-lua are lua plug-ins on vscode. They provide a function of using annotations to enhance lua types. You can try it
You can check the sumneko-lua documentation here: https://github.com/LuaLS/lua-language-server
The original generator is here https://github.com/EmmyLua/Emmy-love-api

The api file looks like this

Code: Select all

---Replaces a range of vertices in the Mesh with new ones. The total number of vertices in a Mesh canno
---  t be changed after it has been created. This is often more efficient than calling Mesh:setVertex in 
---  a loop.
---@param vertices table #The table filled with vertex information tables for each vertex, in the form of {vertex, ...} whe...
---@param startvertex number #The index of the first vertex to replace.
---@overload fun(data:Data, startvertex:number): nil
---@overload fun(vertices:table): nil
function Mesh:setVertices(vertices, startvertex) end

---Clears the screen or active Canvas to the specified color.
---This function is called automatically before love.draw in the default love.run function. See the exa
---  mple in love.run for a typical use of this function.
---Note that the scissor area bounds the cleared region.
---In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 
---  1.
---In versions prior to background color instead.
---@overload fun(r:number, g:number, b:number, a:number, clearstencil:boolean, cleardepth:boolean): nil
---@overload fun(color:table, ...:table, clearstencil:boolean, cleardepth:boolean): nil
---@overload fun(clearcolor:boolean, clearstencil:boolean, cleardepth:boolean): nil
function love.graphics.clear() end
Attachments
generator.lua
(8.2 KiB) Downloaded 123 times
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests