Mercurial > pymonkey
comparison docs/rendered/_sources/pymonkey.txt @ 139:d08cb5a06c66
Added docs for Script, compile_script() and execute_script().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 24 Aug 2009 11:39:58 -0700 |
parents | 0c81cb18c935 |
children | 96dc1beefc00 |
comparison
equal
deleted
inserted
replaced
138:1a982ee56458 | 139:d08cb5a06c66 |
---|---|
52 .. class:: Function | 52 .. class:: Function |
53 | 53 |
54 This is the type of JavaScript functions, which is a subtype of | 54 This is the type of JavaScript functions, which is a subtype of |
55 :class:`Object`. | 55 :class:`Object`. |
56 | 56 |
57 .. class:: Script | |
58 | |
59 This is the type of compiled JavaScript scripts; it's actually a | |
60 subtype of :class:`Object`, though when exposed to JS code it | |
61 doesn't provide access to any special data or functionality. | |
62 | |
63 Script instances have a read-only buffer interface that exposes | |
64 their bytecode. This can be accessed by passing an instance to | |
65 Python's built-in ``buffer()`` function. | |
66 | |
57 .. class:: Context | 67 .. class:: Context |
58 | 68 |
59 This is the type of JavaScript context objects. Contexts can only | 69 This is the type of JavaScript context objects. Contexts can only |
60 be created via a call to :meth:`Runtime.new_context()`, but this | 70 be created via a call to :meth:`Runtime.new_context()`, but this |
61 type object can be used with Python's built-in :func:`isinstance()` | 71 type object can be used with Python's built-in :func:`isinstance()` |
170 | 180 |
171 >>> cx = pymonkey.Runtime().new_context() | 181 >>> cx = pymonkey.Runtime().new_context() |
172 >>> obj = cx.new_object() | 182 >>> obj = cx.new_object() |
173 >>> cx.init_standard_classes(obj) | 183 >>> cx.init_standard_classes(obj) |
174 >>> cx.evaluate_script(obj, '5 * Math', '<string>', 1) | 184 >>> cx.evaluate_script(obj, '5 * Math', '<string>', 1) |
185 nan | |
186 | |
187 .. method:: compile_script(obj, code, filename, lineno) | |
188 | |
189 Compiles the given string of code and returns a :class:`Script` | |
190 instance that can be executed via :meth:`execute_script()`. | |
191 | |
192 `filename` and `lineno` are used just as in | |
193 :meth:`evaluate_script()`. | |
194 | |
195 `obj` is defined in the SpiderMonkey documentation to be | |
196 the "object with which the script is associated", though it's | |
197 unclear what its actual role is. | |
198 | |
199 .. method:: execute_script(globalobj, script) | |
200 | |
201 Executes the code in the given :class:`Script` object, using | |
202 `globalobj` as the global object/scope, and returns the result. | |
203 | |
204 For example: | |
205 | |
206 >>> cx = pymonkey.Runtime().new_context() | |
207 >>> obj = cx.new_object() | |
208 >>> cx.init_standard_classes(obj) | |
209 >>> script = cx.compile_script(cx.new_object(), '5 * Math', | |
210 ... '<string>', 1) | |
211 >>> cx.execute_script(obj, script) | |
175 nan | 212 nan |
176 | 213 |
177 .. method:: call_function(thisobj, func, args) | 214 .. method:: call_function(thisobj, func, args) |
178 | 215 |
179 Calls a JavaScript function. | 216 Calls a JavaScript function. |