Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/PercPush1.lua.html
--   http://anggtwu.net/LUA/PercPush1.lua
--          (find-angg "LUA/PercPush1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/PercPush1.lua"))
-- Used in:
--   (c2m241exprsp 7 "percpush")
--   (c2m241exprsa   "percpush")

require "Show2"     -- (find-angg "LUA/Show2.lua")
require "Stack1"    -- (find-angg "LUA/Stack1.lua")

defs.percpush = [=[
  \def\undcolor#1#2{{\color{#1}\underbrace{\color{black}#2}{}}}
  \def\unda#1{\undcolor{black}{#1}}
  \def\undb#1{\undcolor{orange}{#1}}
]=]

table.addentries(Stack.__index, {
  popn = function (s,n)
      local r = HTable {}
      for i=#s-n+1,#s do table.insert(r, s[i]) end
      s:dropn(n)
      return r
    end,
  perccount  = function (s,str) return #(str:gsub("[^%%]", "")) end,
  perc_u     = function (s,a) return format(" \\unda{%s}{} ", a) end,
  perc_b     = function (s,a) return format(" \\undb{%s}{} ", a) end,
  percsubst0 = function (s,fmt)
      local n=0
      local f = function (c) n=n+1; return format("[%d:%s]", n, c) end
      return (fmt:gsub("%%(.)", f))
    end,
  percsubst1 = function (s,fmt,L)
      local n=0
      local f = function (c)
          n=n+1
          return s["perc_"..c](s, L[n])
        end
      return (fmt:gsub("%%(.)", f))
    end,
  percpush = function (s,fmt)
      local n = s:perccount(fmt)
      if n==0 then s:push(fmt); return s end
      local L = s:popn(n)
      s:push(s:percsubst1(fmt, L))
      return s
    end,
})


--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "PercPush1.lua"

s = Stack.new()
= s:push(10):push(20):push(30):push(40):push(50):push(60):push(70)
= s:popn(2)
= s
= s:perccount"foo%abarplic%bcc"
= s:percsubst0 "foo%abarplic%bcc"
= s:percsubst1("foo%ubarplic%ucc", {20, 30})
= s
= s:percpush("a")
= s:percpush("b%uc%ud")

percdo = function (bigstr)
    local s = Stack.new()
    for _,w in ipairs(split(bitrim(bigstr))) do s:percpush(w) end
    return s[1]
  end

= percdo [=[   a b  f(%u,%u) c %u+%u ]=]
= percdo [=[   a b  f(%u,%u) c %u+%u ]=] :show({em=1})
= percdo [=[ f a b %b(%u,%u) c %u+%u ]=] :show({em=1})
= Show.bigstr
= Show.log
* (etv)

--]==]





-- Local Variables:
-- coding:  utf-8-unix
-- End: