2024-07-29 04:15:54 +02:00
|
|
|
// This is old code but works, so i won't touch it ¯\_(ツ)_/¯
|
|
|
|
|
|
|
|
function str2C(s) {
|
|
|
|
var size = lengthBytesUTF8(s) + 1;
|
|
|
|
var ret = _malloc(size);
|
|
|
|
stringToUTF8Array(s, HEAP8, ret, size);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-07-31 00:48:48 +02:00
|
|
|
window.runEval = function (inputText, stopAssignments = false) {
|
2024-07-29 04:15:54 +02:00
|
|
|
console.log("input: " + inputText);
|
|
|
|
var inputPtr = str2C(inputText);
|
2024-07-31 00:48:48 +02:00
|
|
|
var resultPointer = Module._eval(inputPtr, stopAssignments);
|
2024-07-29 04:15:54 +02:00
|
|
|
|
|
|
|
var resultString = "";
|
|
|
|
|
|
|
|
// Convert resultPointer (char*) to JavaScript string
|
|
|
|
// Here, we treat it as ASCII and convert byte by byte
|
|
|
|
if (resultPointer) {
|
|
|
|
var i = 0;
|
|
|
|
while (true) {
|
2024-07-31 00:48:48 +02:00
|
|
|
var charCode = Module.getValue(resultPointer + i, 'i8');
|
2024-07-29 04:15:54 +02:00
|
|
|
if (charCode === 0) break;
|
|
|
|
resultString += String.fromCharCode(charCode);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("Result from eval:", resultString);
|
|
|
|
|
|
|
|
// Free allocated memory
|
|
|
|
_free(resultPointer);
|
|
|
|
|
|
|
|
return resultString;
|
|
|
|
}
|