Skip to content

Convert ldoc lua documentation into TypeScript types for use with TypeScriptToLua.

License

Notifications You must be signed in to change notification settings

jf908/ldoc-to-tsdoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ldoc to tsdoc

Convert ldoc lua documentation into TypeScript types for use with TypeScriptToLua.

How to use

Requires - ldoc

Place config.ld and ldoc.ltp in the same directory as your lua files and run:

lua ./path/to/ldoc.lua .

If you just want to use it on one file, you can run

lua ./path/to/ldoc.lua file.lua

Example

example.lua index.d.ts
--[[-
This is a demonstration module.
]]

--[[- This is a description of the test function.
@tparam number a The first number to add.
@tparam number b The second number to add.
@treturn boolean Whether the test was successful.]]
function test(a, b) end
/**
 * This is a demonstration module.
 */
declare module 'example' {
  /**
   * This is a description of the test function.
   * @param a The first number to add.
   * @param b The second number to add.
   * @returns boolean - Whether the test was successful.
   */
  export function test(a: number, b: number): boolean;
}

How it works

ldoc is usually used to generate HTML pages from lua but it is possible to configure the template and the file extension of the output so this project uses those config options to generate d.ts files.

Notes

The conversion may not be perfect since it is limited to what is contained in the ldoc syntax so you may have to modify the types to fully make use of TypeScript's type system. Using this template will give you a good starting point regardless. You may also wish to use a formatter like prettier to neaten things up.

By default this template assumes each lua file is a module. You can change it to see files as globals using the as_globals flag at the top to false.

jsdoc and tsdoc are incredibly similar but tsdoc avoids repetition of types. It should be trivial to modify ldoc.ltp to support jsdoc syntax.

About

Convert ldoc lua documentation into TypeScript types for use with TypeScriptToLua.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages