-
-
Save halemmerich/a2e90fc2ea1aefd2bed8a20d3fb3bdf0 to your computer and use it in GitHub Desktop.
Trying to autowrap function in Bangle.js
This file contains 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
let app = "iconlaunch.app.js"; | |
function wrap(name, levels, filter, parent){ | |
if (levels == 0) return; | |
print("Level", levels, name); | |
let o = parent[name]; | |
Object.keys(o).forEach((key)=>{ | |
if (key == "wrap" || filter.includes(key)) return; | |
print("is array", Object.keys(o[key])); | |
if(typeof o[key] === "function" && Object.keys(o[key]).length == 0){ | |
print("Wrapping", name + "." + key); | |
o[key] = (orig => (a,b,c,d,e,f,g,h,i,j,k,l) => { | |
print("called" , name + "." + key); | |
let time = Date.now(); | |
if (orig.___accTime == undefined) orig.___accTime = 0; | |
let result = orig(a,b,c,d,e,f,g,h,i,j,k,l); | |
let diff = Date.now() - time; | |
orig.___accTime += diff; | |
print("finished", name + "." + key, "t:", diff.toFixed(0), "acc:", orig.___accTime.toFixed(0)); | |
return result; | |
})(o[key]); | |
} else { | |
print("Descent", key); | |
wrap(key, levels - 1, filter, o); | |
} | |
}); | |
} | |
wrap("Bangle",2,["Object"], global); | |
wrap("E",1,["Object"], global); | |
eval(require("Storage").read(app)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment