lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 06/11/2017 04:15 PM, Sean Conner wrote:
>   For example, this function:
> 	function encode(value,sref,stref)
> 	  local res = ""
> 	  if stref and not stref.SEEN then
> 	    res = TAG._stringref(nil,nil,stref)
> 	  end
> 	  return res .. __ENCODE_MAP[type(value)](value,sref,stref)
> 	end
> such a tool could return:
> 	--- Placeholder
> 	-- @function encode
> 	-- @param value
> 	-- @param sref
> 	-- @param stref
> 	-- @return
> 	function encode(value,sref,stref)
> 	...
>   -spc (I don't understand the full scope of this, so of course it must be
> 	trivial! 8-P

Hmm, as experiment I can create a breed of lua code formatter which
produces output with such autogenerated comments. But is there really
need for this?

Function in Lua may be defined in three ways:

1. "local function <name> (<args>)" //<name> can't contain ":" syntel
2. "function <name> (<args>)"
3. "function (<args>)"

Most obscure case is (3). It is often used as expression for sort() or
gsub(). Do you have a good heuristic how do decide emit/not_emit header
for function, given annotated syntax tree of source?

And by the way, are there good ways to test such formatter? Creating yet
another rock with name like "lcf.experiments" looks like a bad idea.

-- Martin