X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/574d47203e63ac4a85f0d609098118d19e6bbf09..a2beb6bb38a621db8c9ddce9500aea738f1c62ee:/libcycript.cy diff --git a/libcycript.cy b/libcycript.cy index 4014fd6..3517e73 100644 --- a/libcycript.cy +++ b/libcycript.cy @@ -83,6 +83,97 @@ $cy_set(RegExp.prototype, { }, }); +if ("Java" in Cycript) { + $cy_set(java.lang.Boolean.prototype, { + toCYON: function() { + return `new java.lang.Boolean(${this->value})`; + }, + }); + + $cy_set(java.lang.Byte.prototype, { + toCYON: function() { + return `new java.lang.Byte(${this->value})`; + }, + }); + + $cy_set(java.lang.Character.prototype, { + toCYON: function() { + return `new java.lang.Character(${this->value})`; + }, + }); + + $cy_set(java.lang.Short.prototype, { + toCYON: function() { + return `new java.lang.Short(${this->value})`; + }, + }); + + $cy_set(java.lang.Integer.prototype, { + toCYON: function() { + return `new java.lang.Integer(${this->value})`; + }, + }); + + $cy_set(java.lang.Long.prototype, { + toCYON: function() { + return `new java.lang.Long(${this->value})`; + }, + }); + + $cy_set(java.lang.Float.prototype, { + toCYON: function() { + return `new java.lang.Float(${this->value})`; + }, + }); + + $cy_set(java.lang.Double.prototype, { + toCYON: function() { + return `new java.lang.Double(${this->value})`; + }, + }); + + $cy_set(java.lang.Object.prototype, { + toCYON: function(key) { + return "#" + this.toString().toCYON(); + }, + + // XXX: due to lack of interface prototypes :( + $cyg: function(key) { + return this.get(key); + }, + + // XXX: due to lack of interface prototypes :( + $cys: function(key, value) { + if ("set" in this) + this.set(key, value); + else + this.put(key, value); + }, + }); +} + +if ("ObjectiveC" in Cycript) { + $cy_set(NSArray.prototype, { + $cyg: function(key) { + return objc_msgSend(this, "objectAtIndex:", key); + }, + + $cys: function(key, value) { + return objc_msgSend(this, "setObject:atIndex:", value, key); + }, + }); + + $cy_set(NSDictionary.prototype, { + $cyg: function(key) { + return objc_msgSend(this, "objectForKey:", key); + }, + + $cys: function(key, value) { + return objc_msgSend(this, "setObject:forKey:", value, key); + }, + }); +} + let IsFile = function(path) { // XXX: this doesn't work on symlinks, but I don't want to fix stat :/ return access(path, F_OK) == 0 && access(path + '/', F_OK) == -1;