Last active
August 29, 2015 14:26
-
-
Save avdg/dd911ca85e0570aeaf42 to your computer and use it in GitHub Desktop.
Screeps fetch api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var writeApiData = function() { | |
var parseFunction = function(obj) { | |
// Note: Function.prototype.toString() is implementation defined, may not work on non-v8 or future v8 js engines | |
// See: http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.2 | |
var args = obj.toString(); | |
args = args.substr(0, args.indexOf(")")); | |
args = args.substr(args.indexOf("(") + 1); | |
args = args === "" ? [] : args.split(","); | |
var data = { | |
"_type": "function", | |
"_args": args | |
}; | |
for (var j in obj) { | |
if (typeof obj[i] === "function" && i !== "toString" && i !== "_") { | |
data[i] = parseFunction(obj[i]); | |
continue; | |
} | |
data[j] = typeof obj[j]; | |
} | |
if (typeof obj.prototype !== "object") { | |
return data; | |
} | |
for (var i in obj.prototype) { | |
if (typeof obj.prototype[i] === "function") { | |
data[":" + i] = parseFunction(obj.prototype[i]); | |
continue; | |
} | |
data[":" + i] = typeof obj.prototype[i]; | |
} | |
return data; | |
}; | |
var data = {}; | |
for (var i in globals) { | |
if (typeof globals[i] === "function") { | |
data[i] = parseFunction(globals[i]); | |
continue; | |
} | |
if (typeof globals[i] === "object" && i !== "Memory") { | |
data[i] = { | |
"_type": "object" | |
}; | |
for (var k in globals[i].prototype) { | |
data[i][k] = typeof globals[i]; | |
} | |
continue; | |
} | |
data[i] = typeof globals[i]; | |
} | |
console.log("### apidata: " + JSON.stringify(data)); | |
} | |
writeApiData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment