summaryrefslogtreecommitdiff
path: root/tests/projects/nim/link_library/static.nim
blob: 6808d589524c1b610212a3e25bb3306117ae67e4 (plain)
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
proc addTwo*(x: int): int =
  return x + 2

proc getAlphabet*(): string =
  for letter in 'a'..'z':
    result.add(letter)

{.emit: """
#define TEST_STATIC
#include "test.h"
""".}

proc getMsg*(): cstring {.exportc, dynlib.} =
    var msg: cstring
    {.emit: "`msg` = TEST_MSG;".}
    return msg

{.emit: """
#include <test_header.h>
""".}

var testHeaderVal {.importc: "TEST_HEADER_VAL", nodecl.}: cint
echo "TEST_HEADER_VAL: ", testHeaderVal

proc test_add_five(x: cint): cint {.importc: "test_add_five", nodecl.}
echo "test_add_five(60): ", test_add_five(60)