-- -- $Header: /Users/dap/lua/RCS/ScratchIO.lua,v 1.1 2007/02/11 08:40:26 dap Exp $ -- -- Author (a) 2007, Damon Anton Permezel. All bugs revered. -- -- scratch.lua - source this in some VoodooPad scripts -- -- Usage: --[[ package.path = package.path .. ';/Users/dap/lua/?.lua' p=require("ScratchIO"):new {} p:out('Hello world @ %s', os.date('%Y-%m %A %T')) --]] -- module(..., package.seeall) -- -- The assumption here is that we will use a VoodooPad buffer named -- '*sscratch*' for the output of the scripts we will be typing in a -- buffer. -- ScratchIO=require'PageIO':subclass { key = '*scratch*', nlines = 48, ncol = 80, attr = { background = 'yellow', font = { name = 'Monaco', size = 12 }, }, extant = nil, } function ScratchIO:init() if ScratchIO.extant then error('at most one instance') else ScratchIO.extant = self end self:seek(0) self:deleteToEOP() self:insert(((' '):rep(self.ncol) .. '\n'):rep(self.nlines), self.attr) self:seek(0) end function ScratchIO:out(fmt, ...) if fmt and type(fmt) == 'string' then self:replace(fmt:format(unpack(arg)) .. '\n', self.attr) else self:replace(('*** non string format %s'):format(tostring(fmt))) end self:display() end return ScratchIO