-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
53 lines (41 loc) · 977 Bytes
/
main.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
45
46
47
48
49
50
51
52
#include "TinyCInterpreter.h"
#include <stdio.h>
#include <fstream>
#include <string.h>
int static read_full_content(const std::string& filePath, std::string& out) {
std::ifstream ifs(filePath.c_str());
if (!ifs.is_open()) {
return -1;
}
ifs.seekg(0, std::ios::end);
int size = ifs.tellg();
ifs.seekg(0, std::ios::beg);
char buff[size+1];
ifs.read(buff, size);
ifs.close();
out.assign(buff, size);
return 0;
}
double foo(int a) {
return a + 1;
}
int bar() {
return 10 + 2;
}
typedef double (*proc_wrapped)(int arg);
typedef double (*proc_wrapped1)();
int main()
{
c99Interpreter c99;
{
std::string content;
read_full_content("../test.tcc", content);
c99.setSearchPath("../");
c99.compileScript(content.c_str(), "test.tcc");
c99.addCustomSymbols("foo", (void*)foo);
c99.buildSymbol("test.tcc");
proc_wrapped func = (proc_wrapped)c99.getFunInScript("test.tcc", "wrapped");
printf("%p, %lf\n", func, func(100));
}
return 0;
}