Code Monkey home page Code Monkey logo

Comments (4)

stevedonovan avatar stevedonovan commented on May 30, 2024

It's indeed possible to get the output you want - look at how the [opt] and [optchain] options are used in this example:

--- options.lua
-- optional arguments
module 'options'

--- Function with an optional arg.
-- @param a
-- @param[opt] b
function fun(a, b, c)
end

--- Function with two optional args.
-- This returns one of our own types
-- @param a
-- @param[opt] b
-- @param[optchain] c
-- @return @{mytype}
function fun(a, b, c)
end

--- a custom table
-- @field x
-- @field y
-- @table mytype

The difference between opt and optchain is that you then get (a,[ b [,c]]) instead of (a[,b\[,c]).

That also has a reference to a table in the same module - it becomes a link. Of course, you can make a link to a type or function in another module and then things get interesting!

As for param[opt], I am not entirely satisfied with this syntax. It feels a little hard on the fingers and the eyes!

from ldoc.

Yonaba avatar Yonaba commented on May 30, 2024

I just tried, and it worked flawlessly. Thanks!
I missed that feature, as I just went through the md file (docs/md), and the param[opt] feature isn't described there. Maybe it should incuded ?

Anyway, it remains a last point. Something in the output is odd, to me.

--- Function with an optional arg.
-- @param a
-- @param[opt] b
-- @param c
function fun(a, b, c)
end

Will produce this (html)

fun (a[, b], c)

which seems perfect, but it wouldn't it be a bit more clean to have a space character right before the "[" character ?

fun (a [, b], c)

That's the exact way how functions are described in the all Lua Reference Manuals, and it looks really nice, this way.

from ldoc.

stevedonovan avatar stevedonovan commented on May 30, 2024

Yes, let me document this feature now before I forget.

I agree with you that there should be a space there; it becomes more readable!

from ldoc.

alerque avatar alerque commented on May 30, 2024

This seems to have been addressed already.

from ldoc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.