2

In Lua Development Tools, how do I document that an input parameter is a table of some type?

mynamespace = {}

---
-- @type mynamespace.MyClass
-- @field #number var1
mynamespace.MyClass = {}

---
-- @param #number param1
-- @return #mynamespace.MyClass
function mynamespace.MyClass.new(param1)
    local self = mynamespace.MyClass
    self.var1 = param1
    return self
end


---
-- @param WHAT_DO_I_WRITE_HERE arrayOfMyClass
function processArrayOfMyClass(arrayOfMyClass)
    for i=1, #arrayOfMyClass do
        instanceOfMyClass = arrayOfMyClass[i]
        -- ... do something with an element of the array
    end
end

EDIT: Sorry, guys. Seems this documentation was LDT (Lua Development Tools) exclusive. I'll update my question

birgersp
  • 3,909
  • 8
  • 39
  • 79
  • `-- @param arrayOfMyClass It is a table of some sort.` [docs](https://keplerproject.github.io/luadoc/manual.html#tags) – Aki Sep 27 '16 at 16:36
  • Could you please elaborate on that comment? – birgersp Sep 27 '16 at 17:07
  • 1
    `@param ` you just describe the table. there is nothing to put between `@param` and the param name. I cannot find `#` in the luadoc reference. what effect should `#number` have? – Piglet Sep 27 '16 at 18:03

2 Answers2

1

I ended up using --@param #list<#bajas.ReinforcementSetup> reinforcementSetups, works like a charm!

Found it in the LDT docs, here: https://wiki.eclipse.org/LDT/User_Area/Documentation_Language#Structure_types

mynamespace = {}

---
-- @type mynamespace.MyClass
-- @field #number var1
mynamespace.MyClass = {}

---
-- @param #number param1
-- @return #mynamespace.MyClass
function mynamespace.MyClass.new(param1)
    local self = mynamespace.MyClass
    self.var1 = param1
    return self
end


---
-- @param #list<#mynamespace.MyClass> arrayOfMyClass
function processArrayOfMyClass(arrayOfMyClass)
    for i=1, #arrayOfMyClass do
        instanceOfMyClass = arrayOfMyClass[i]
        -- ... do something with an element of the array
    end
end
birgersp
  • 3,909
  • 8
  • 39
  • 79
-1

You can use type(val) to verify the type of data being passed, and return an effective error message to describe the mistake to the coder.

warspyking
  • 3,045
  • 4
  • 20
  • 37
  • "How do I _document_ that an input parameter is a table of some type in Lua?" Runtime errors are not documentation. – Oka Sep 28 '16 at 06:21
  • 1
    No but it should be used in cooperation with. Documenting is easy, you should make a comment :P @oka – warspyking Sep 28 '16 at 09:47