-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtext.js
45 lines (42 loc) · 1.29 KB
/
text.js
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
var ffi = require("node-ffi");
var fs = require("fs");
function DynLib(){
var request = [];
fs.readFile('base.txt', 'UTF-8', function (err, text) {
if (err) throw err;
curPos = 0;
endPos = 0;
while (text.indexOf("\n", curPos) != -1) {
endPos = text.indexOf("\n", curPos);
if (endPos == -1)
{ endPos = text.length}
request.push(text.slice(curPos, endPos));
curPos = endPos + 1;
}
// console.log("req: ", request);
StructForLib = new Object();
for(i=0; i < request.length -1; i++) {
curPos = 0;
endPos = 0;
returnType = "";
funcName = "";
funcType = [];
endPos = request[i].indexOf(",", curPos);
funcName = request[i].slice(curPos, endPos) +"";
curPos = endPos + 1;
endPos = request[i].indexOf(",", curPos);
returnType = request[i].slice(curPos, endPos);
curPos = endPos + 1;
while (request[i].indexOf(",", curPos) != -1) {
endPos = request[i].indexOf(",", curPos);
funcType.push(request[i].slice(curPos, endPos));
curPos = endPos + 1;
}
StructForLib[funcName] = [returnType, funcType];
}
libName ="./" + request[request.length - 1];
lib1 = ffi.Library(libName, StructForLib);
console.log("StructForLib = "); console.log(StructForLib);
});
}
exports.DynLib = DynLib; //externs the func to other files