Saturday, October 12, 2013

Typhoon Nari

I have been back in the Philippines for about a month now, the weather this year has been more wet than it normally is. Two nights ago Typhoon Nari hit us hard in Tarlac, these are the most powerful winds I have ever seen. Now two days after, the city is still without power. I have been charging my laptop at the generator-powered bus station and using their free wifi, at least until the security guard caught me today using the power plug that is supposed to power the pump for the goldfish pond. I tried to explain to him that gold fish do not need much oxygen, but he was not hearing me out.

Until power is restored at home, I won't be able to do much work on PythonScript. However, I am still working on what I can. Today I improved the way JavaScript can be inlined into PythonScript. Previously to inline JavaScript you had to wrap it in JS("some javascript code"), this becomes tedious after awhile. The new style to inline JavaScript is using the with statement like this: with javascript: When you enter a with javascript: block the compiler will switch into a different mode where you can create JavaScript Arrays and Objects using Python's literal list and dict syntax; this is a shortcut for calling JSArray() and JSObject().

with javascript:

<script src="pythonscript.js"></script>

<script type="text/python">

a = 'hello'
b = 'world'

def test():

 with javascript:
  arr = []
  arr[1] = 'world'
  ob = { x:'foo', y:'bar'}
  console.log( arr )
  console.log( ob )


<button onclick="test()">click me</button>

No comments:

Post a Comment