forked from flightaware/cpptcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample6.cc
44 lines (32 loc) · 872 Bytes
/
example6.cc
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
34
35
36
37
38
39
40
41
42
43
44
// example6.cc
#include <iostream>
#include "cpptcl/cpptcl.h"
using namespace std;
using namespace Tcl;
int main() {
Tcl_Interp * interp = Tcl_CreateInterpWithStubs("8.6", 0);
interpreter i(interp, true);
int numbers[] = {5, 7, 1, 6, 3, 9, 7};
size_t elems = sizeof(numbers) / sizeof(int);
object tab;
for (size_t indx = 0; indx != elems; ++indx) {
tab.append(object(numbers[indx]));
}
object cmd("lsort -integer");
cmd.append(tab);
// here, cmd contains the following:
// lsort -integer {5 7 1 6 3 9 7}
object result = i.eval(cmd);
cout << "unsorted: ";
for (size_t indx = 0; indx != elems; ++indx) {
cout << numbers[indx] << ' ';
}
cout << "\n sorted: ";
elems = result.size();
for (size_t indx = 0; indx != elems; ++indx) {
object obj(result.at(indx));
int val = obj.get<int>();
cout << val << ' ';
}
cout << '\n';
}