A simple example from the README:
require "johnson" Johnson.evaluate("4 + 4") # => 8 Johnson.evaluate("4 + foo", :foo => 4) # => 8
$ johnson js> 1 + 1 => 2 js> var name = 'chris' => nil js> name => "chris"
Also you can use it to execute a buffer:
(defun js2-execute-buffer () (interactive) (shell-command (concat "johnson " (buffer-file-name))))
Or a single line:
(defun js2-execute-line () (interactive) (save-excursion (call-process-region (point-at-bol) (point-at-eol) "johnson" nil (get-buffer-create "*johnson-line*")) (with-current-buffer (get-buffer "*johnson-line*") (search-backward "\n\n" nil t) (replace-match "" nil t) (message (buffer-string)) (kill-buffer nil))))
I bind these functions to
(define-key js2-mode-map (kbd "A-r") 'js2-execute-buffer) (define-key js2-mode-map (kbd "A-R") 'js2-execute-line)
It’s very similar to Johnson. Except, you know, for Python.
>>> import spidermonkey >>> rt = spidermonkey.Runtime() >>> cx = rt.new_context() >>> cx.execute("var x = 3; x *= 4; x;") 12
Again, the README has it all.