Created
July 17, 2012 18:32
-
-
Save Neppord/3131140 to your computer and use it in GitHub Desktop.
Pyjaco Discussion
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
class MyClass: | |
value = 0 | |
"""jsspace | |
MyClass.value = 0; | |
""" |
dxlbnl
commented
Jul 17, 2012
o = py(jQuery);
o.PY$__getattr__("click").__call__($c42, $PY.str("foo"));
py('path.to.jsorpyvar', pyvar) //setting a value from a python typed var
js('path.to.jsorpyvar', jsvar) //setting a value from a javascript typed var
py('path.to.some.var.and.typecast.it.outmaticaly.to.py')
// pure js
$("#mydiv").click(function() { alert("foo"); }
// translated
jq = py(jQuery);
jq.PY$__call__($PY.str("#mydiv")).PY$__getattr__("click").PY$__call__(py(function() { py(alert).PY$__call__($PY.str("foo")); )};
// pure js
$("#mydiv").click(function() { alert("foo"); }
// translated
jq = py(jQuery);
jq.PY$__call__(py("#mydiv")).PY$__getattr__("click").PY$__call__(py(function() { py(alert).PY$__call__($PY.str("foo")); )};
var py = function(obj) {
if (obj && obj.PY$__class__ !== undefined) {
return obj;
} else if (typeof obj === 'number') {
return int(obj);
} else if (typeof obj === 'string') {
return str(obj);
} else if (typeof obj === 'boolean') {
return bool(obj);
} else if (obj === undefined || obj === null) {
return None;
} else if (obj instanceof Array) {
var res = list();
for (var q in obj) {
res.PY$append(py(obj[q]));
}
return res;
} else {
var res = dict();
for (var q in obj) {
res.PY$__setitem__(str(q), py(obj[q]));
}
return res;
}
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment