userdata = userdata or { } userdata.t = { { 0, 0, 0, }, { 0, 0, 1, }, { 0, 1, 0, }, { 0, 1, 1, }, { 1, 0, 0, }, { 1, 0, 1, }, { 1, 1, 0, }, { 1, 1, 1, }, } --- Lua stuff 1 ------------------------------------------------- userdata.env = [[ \starttable[%s] \HL %s \HL \stoptable ]] local fmt, rep, unpack = string.format, string.rep, table.unpack userdata.do_typesetatable = function (t) local maxx, maxy, lines = #t[1], #t, { } local template = rep("\\NC %s", maxx) for n=1, maxy do local row = t[n] lines[n] = " " .. fmt(template, unpack(row)) .. "\\AR" end context( fmt(userdata.env, "|" .. rep("c|", maxx), table.concat(lines, "\n")) ) end --- Lua stuff 2 ------------------------------------------------- local AR, HL, NC = context.AR, context.HL, context.NC userdata.do_typesetcldtable = function (t) local maxx, maxy = #t[1], #t context.starttable({ "|" .. rep("c|", maxx) }) HL() for n=1, maxy do local row = t[n] for m=1, maxx do NC() context(row[m]) end AR() end HL() context.stoptable() end