| [1650] | 1 | -- tolua: verbatim class | 
|---|
|  | 2 | -- Written by Waldemar Celes | 
|---|
|  | 3 | -- TeCGraf/PUC-Rio | 
|---|
|  | 4 | -- Jul 1998 | 
|---|
|  | 5 | -- $Id: verbatim.lua,v 1.3 2000/01/24 20:41:16 celes Exp $ | 
|---|
|  | 6 |  | 
|---|
|  | 7 | -- This code is free software; you can redistribute it and/or modify it. | 
|---|
|  | 8 | -- The software provided hereunder is on an "as is" basis, and | 
|---|
|  | 9 | -- the author has no obligation to provide maintenance, support, updates, | 
|---|
|  | 10 | -- enhancements, or modifications. | 
|---|
|  | 11 |  | 
|---|
|  | 12 |  | 
|---|
|  | 13 |  | 
|---|
|  | 14 | -- Verbatim class | 
|---|
|  | 15 | -- Represents a line translated directed to the binding file. | 
|---|
|  | 16 | -- The following filds are stored: | 
|---|
|  | 17 | --   line = line text | 
|---|
|  | 18 | classVerbatim = { | 
|---|
| [2710] | 19 | line = '', | 
|---|
|  | 20 | cond = nil,    -- condition: where to generate the code (s=suport, r=register) | 
|---|
| [1650] | 21 | } | 
|---|
|  | 22 | classVerbatim.__index = classVerbatim | 
|---|
|  | 23 | setmetatable(classVerbatim,classFeature) | 
|---|
|  | 24 |  | 
|---|
|  | 25 | -- preamble verbatim | 
|---|
|  | 26 | function classVerbatim:preamble () | 
|---|
| [2710] | 27 | if self.cond == '' then | 
|---|
|  | 28 | write(self.line) | 
|---|
|  | 29 | end | 
|---|
| [1650] | 30 | end | 
|---|
|  | 31 |  | 
|---|
|  | 32 | -- support code | 
|---|
|  | 33 | function classVerbatim:supcode () | 
|---|
| [2710] | 34 | if strfind(self.cond,'s') then | 
|---|
|  | 35 | write(self.line) | 
|---|
|  | 36 | write('\n') | 
|---|
|  | 37 | end | 
|---|
| [1650] | 38 | end | 
|---|
|  | 39 |  | 
|---|
|  | 40 | -- register code | 
|---|
|  | 41 | function classVerbatim:register (pre) | 
|---|
| [2710] | 42 | if strfind(self.cond,'r') then | 
|---|
|  | 43 | write(self.line) | 
|---|
|  | 44 | end | 
|---|
| [1650] | 45 | end | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
|  | 48 | -- Print method | 
|---|
|  | 49 | function classVerbatim:print (ident,close) | 
|---|
| [2710] | 50 | print(ident.."Verbatim{") | 
|---|
|  | 51 | print(ident.." line = '"..self.line.."',") | 
|---|
|  | 52 | print(ident.."}"..close) | 
|---|
|  | 53 | end | 
|---|
| [1650] | 54 |  | 
|---|
|  | 55 |  | 
|---|
|  | 56 | -- Internal constructor | 
|---|
|  | 57 | function _Verbatim (t) | 
|---|
| [2710] | 58 | setmetatable(t,classVerbatim) | 
|---|
|  | 59 | append(t) | 
|---|
|  | 60 | return t | 
|---|
| [1650] | 61 | end | 
|---|
|  | 62 |  | 
|---|
|  | 63 | -- Constructor | 
|---|
|  | 64 | -- Expects a string representing the text line | 
|---|
|  | 65 | function Verbatim (l,cond) | 
|---|
| [2710] | 66 | if strsub(l,1,1) == "'" then | 
|---|
|  | 67 | l = strsub(l,2) | 
|---|
|  | 68 | elseif strsub(l,1,1) == '$' then | 
|---|
|  | 69 | cond = 'sr'       -- generates in both suport and register fragments | 
|---|
|  | 70 | l = strsub(l,2) | 
|---|
|  | 71 | end | 
|---|
|  | 72 | return _Verbatim { | 
|---|
|  | 73 | line = l, | 
|---|
|  | 74 | cond = cond or '', | 
|---|
|  | 75 | } | 
|---|
| [1650] | 76 | end | 
|---|
|  | 77 |  | 
|---|
|  | 78 |  | 
|---|