\usemodule[pre-30]

\StartSample {Access}

\startbuffer
\lua {
    document = { }
    document.dimens = { }
}

\dostepwiserecurse{`a}{`z}{1} {
    \setbox\scratchbox\hbox{\char\recurselevel}
    \lua {
        document.dimens[\recurselevel] = tex.wd[\number\scratchbox]
    }
}

\lua {
    local total, n = 0, 0
    for d in pairs(document.dimens) do
        total, n = total + document.dimens[d], n + 1
    end
    if n>0 then
        document.mean = total/n
    else
        document.mean = 0
    end
}
\stopbuffer

\setups{show-definition}

\startbuffer
\mathematics {
    \lua { tex.dimen[0] = document.mean } \withoutpt \the\dimen0  =
    \lua { tex.print(document.mean/65536) } \approx
    \lua { tex.print(math.ceil(document.mean/65536)) }
}

\bgroup
    \count0=10 \count2=30
    \scratchcounter = \lua { tex.print((tex.count[0] + tex.count[2])/2) }
    \number\scratchcounter
\egroup
\stopbuffer

\setups{show-usage}

\StopSample
