File: since.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (33 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download
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
26
27
28
29
30
31
32
33
##[
`since` is used to emulate older versions of nim stdlib,
see `tuse_version.nim`.

If a symbol `foo` is added in version `(1,3,5)`, use `{.since: (1.3.5).}`, not
`{.since: (1.4).}`, so that it works in devel in between releases.

The emulation cannot be 100% faithful and to avoid adding too much complexity,
`since` is not needed in those cases:
* if a new module is added
* if an overload is added
* if an extra parameter to an existing routine is added
]##

template since*(version: (int, int), body: untyped) {.dirty.} =
  ## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than
  ## or equal to `version`. Usage:
  ##   ```Nim
  ##   proc fun*() {.since: (1, 3).}
  ##   since (1, 3): fun()
  ##   ```
  when (NimMajor, NimMinor) >= version:
    body

template since*(version: (int, int, int), body: untyped) {.dirty.} =
  ## Evaluates `body` if ``(NimMajor, NimMinor, NimPatch)`` is greater than 
  ## or equal to `version`. Usage:
  ##   ```Nim
  ##   proc fun*() {.since: (1, 3, 1).}
  ##   since (1, 3, 1): fun()
  ##   ```
  when (NimMajor, NimMinor, NimPatch) >= version:
    body