-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.py
More file actions
33 lines (22 loc) · 740 Bytes
/
Copy pathadd.py
File metadata and controls
33 lines (22 loc) · 740 Bytes
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
import sys
import os
import ctypes
import argparse
def parse_args():
default_path = os.path.join("..", "libshared", "Debug", "libshared.dll")
parser = argparse.ArgumentParser(description='Adds two integers.')
parser.add_argument('terms', type=int, nargs='+', help='Two terms to sum')
parser.add_argument('--dll', default=default_path)
args = parser.parse_args()
assert len(args.terms) == 2, "takes exactly two parameters"
return args
args = parse_args()
path_to_dll = args.dll
a, b = args.terms
dll = ctypes.cdll.LoadLibrary(path_to_dll)
dll.add.argtypes = (ctypes.c_int, ctypes.c_int)
dll.add.restype = ctypes.c_int
c1 = dll.add(a, b)
c2 = a + b
print(f"C++:\t{c1}")
print(f"python:\t{c2}")