-
Notifications
You must be signed in to change notification settings - Fork 1
/
emcc.js
37 lines (33 loc) · 842 Bytes
/
emcc.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
file_get_contents = function(path) {
var c_string = alloc_string(path);
var ret = _file_get_contents(c_string);
_free(c_string);
return ret;
}
Com_Init = function(commandline) {
var c_string = alloc_string(commandline);
var ret = _Com_Init(c_string);
_free(c_string);
return ret;
}
Cmd_ExecuteString = function(cmd) {
var c_string = alloc_string(cmd);
var ret = _Cmd_ExecuteString(c_string);
_free(c_string);
}
alloc_string = function(str) {
var mem = _malloc(str.length + 1);
for (var i=0; i<str.length; i++) {
HEAP8[mem + i] = str.charCodeAt(i);
//console.log(str.charCodeAt(i));
}
HEAP8[mem + str.length] = 0; // terminate string
return mem;
}
addressToString = function(address) {
var ret = "";
for (var i=address; HEAP8[i]; i++) {
ret += String.fromCharCode( HEAP8[i] );
}
return ret;
}