summaryrefslogtreecommitdiff
path: root/tests/projects/nim/link_library/shared.nim
blob: 58dacc6dfdabbaeef389df3d367c333e857d931b (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
27
28
29
proc mulTwo*(x: int): int =
  return x * 2

import tables, strutils

proc countWords*(input: string): string =
  var wordFrequencies = initCountTable[string]()
  for word in input.split(", "):
    wordFrequencies.inc(word)
  return "The most frequent word is '" & $wordFrequencies.largest & "'"

{.emit: """
#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(10): ", test_add_five(10)