Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
#!/usr/bin/env lua51
-- defwithmanyargs.lua
-- Eduardo Ochs, 2011jan17
-- This file: (find-angg "LUA/defwithmanyargs.lua")
--    http://angg.twu.net/LUA/defwithmanyargs.lua
--    http://angg.twu.net/LUA/defwithmanyargs.lua.html
-- See:
--   (find-es "tex" "more-than-9-args")
--   (find-angg ".emacs" "tex-def-many")

-- «.run»	(to "run")
-- «.test-arg»	(to "test-arg")
-- «.test-run»	(to "test-run")


--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
--]]

name = "foo"
body = "% body\n"
ha  = function (hn)      return format("#%d", hn) end
han = function (np)      return mapconcat(ha, seq(1, np)) end
sa  = function (myn, hn) return format("\\sa{%d}{#%d}", myn, hn) end
saf = function (n)       return function (hn) return sa(5*n + hn, hn) end end
san = function (n, np)   return mapconcat(saf(n), seq(1, np)) end
na  = function (n)       return format("\\%s%s", name, ("@"):rep(n)) end
bg  = function (n)       return n==0 and "\\begingroup" or "" end
-- ga  = function (myn)     return format("\\ga{%d}", myn) end
da = function (n)
    return format("\\def%s%s{%s%%\n", na(n), han(5), bg(n)) ..
           format("  %s%s}\n",        san(n, 5), na(n + 1))
  end
dal = function (n, np)
    return format("\\def%s%s{%%\n", na(n), han(np)) ..
           format("  %s%%\n",       san(n, np)) ..
           body ..
           "  \\endgroup}\n"
  end
fulldef_ = function (np)
    local T = {}
    for n=0,10000 do
      if np > 5
      then tinsert(T, da(n)); np = np - 5
      else tinsert(T, dal(n, np)); break
      end
    end
    return table.concat(T, "")
  end






--[[
    texdef = function (Sh, lower)
        local out = ""
        local printf = function (...) out = out..format(...) end
        local w, h = Sh.width, Sh.height
        local pw = 6 * w + 2
        local ph = 12 * h
        local name = Sh.name
        local args = texargs[Sh.nvertices]
        local plower = (lower or 0) * 12
        printf("\\def\\dag%s%s{%%\n", name, args)
        printf("  \\dagpicture(%d,%d)(-4,0)[%d]{\n", pw, ph, plower)
        for i,xy in ipairs(Sh.coords) do
          local x, y = xy[1], xy[2]
          local px, py = (x-1)*6, (h-y)*12
          printf("    \\dagput(%3d,%3d){$#%d$}\n", px, py, i)
        end
        printf("  }}\n")
        return out
      end,
--]]

-- «run»  (to ".run")
-- (find-angg ".emacs" "tex-def-many")
if arg and arg[1] == "--longdef" then
  name = arg[2]
  np   = tonumber(arg[3])
  body = arg[4] or "% body\n"
  print(fulldef_(np))
end

--[[
-- Tests.
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
ee_dofile "~/LUA/defwithmanyargs.lua"
= fulldef_(16)
= fulldef_(20)
= mapconcat(ha, seq(1, 5))
= mapconcat(saf(3), seq(1, 5))
= da(0)..da(1)..da(2)
= dal(3, 1)
= dal(3, 5)

-- «test-arg»  (to ".test-arg")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
arg = {"--longdef", "sixt", "16"}
ee_dofile "~/LUA/defwithmanyargs.lua"
arg = {"--longdef", "sixt", "20", "% bbooddyy\n% bboo\n"}
ee_dofile "~/LUA/defwithmanyargs.lua"
-- «test-run»  (to ".test-run")
-- (find-sh "~/LUA/defwithmanyargs.lua -run rect 12")
-- (find-sh "~/LUA/defwithmanyargs.lua -run rect 12 '% body\n% body\n'")
-- (find-angg ".emacs" "tex-def-many")

--]]




-- Local Variables:
-- coding:  raw-text-unix
-- modes:   (fundamental-mode lua-mode)
-- End: