In the last days I've reimplemented the CoDScript style "threads" (coroutines) inside JavaScript/Duktape. As test engine I use ET:Legacy, because that's like CoD 0.5, lol.
In the grand scheme, I wanna reimplement CoDScript as a whole and add JavaScript even on the client side, so it's possible to script the clients as server admin at runtime. And since ET has Quake3 heritage, the Quake Virtual Machine is available aswell... endless possibilities, I feel like in the beginning days of CoD2 scripting.
All the JavaScript code I've put together in last days, it's the basemod "algorithm" to move brushes:
PHP Code:
// MIT License, have fun
function sprintf() {
var ret = "";
var param = 1; // maps to first %
var msg = arguments[0];
for (var i=0; i<msg.length; i++) {
if (msg[i] == "%") {
// %% will be printed as normal %
if (msg[i+1] == "%") {
ret += "%";
i++;
} else
ret += arguments[param++];
} else {
ret += msg[i];
}
}
return ret;
}
function printf() {
var ret = "";
var param = 1; // maps to first %
var msg = arguments[0];
for (var i=0; i<msg.length; i++) {
if (msg[i] == "%") {
// %% will be printed as normal %
if (msg[i+1] == "%") {
ret += "%";
i++;
} else
ret += arguments[param++];
} else {
ret += msg[i];
}
}
log(ret);
return ret.length;
}
function require(filename) {
var content = file_get_contents( filename );
try {
eval.bind( get_global() )(content);
} catch (e) {
printf("require(%): error %\n", filename, e.stack);
}
}
if (typeof date_start == "undefined")
date_start = Date.now();
// time since loading this file for first time
function now() {
return Date.now() - date_start;
}
print = function() {
for (var i=0; i<arguments.length; i++) {
log(arguments[i]);
}
}
function var_dump(ret) {
switch (typeof ret) {
case "number": {
print("ret = ", ret, ";");
break;
}
case "string": {
print("ret = \"", ret, "\";");
break;
}
case "function": {
// print infos like byte codes or length of byte codes
print("Function: ", ret);
break;
}
case "boolean": {
print("ret = ", ret, ";");
break;
}
case "object"