summary refs log tree commit diff stats
path: root/tests/ttempl3.nim
blob: 39262497c54b6e1f3293c408ff407ee107801cc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
template withOpenFile(f, filename, mode: expr, actions: stmt): stmt =
  block:
    var f: TFile
    if openFile(f, filename, mode):
      try:
        actions
      finally:
        closeFile(f)
    else:
      quit("cannot open for writing: " & filename)
    
withOpenFile(txt, "ttempl3.txt", fmWrite):
  writeln(txt, "line 1")
  txt.writeln("line 2")
  
# Test zero argument template: 
template ha: expr = myVar[0]
  
var
  myVar: array[0..1, int]
  
ha = 1  
echo(ha)