On Mon, Feb 3, 2014 at 2:42 PM, Péter Szilágyi <
pet...@gmail.com> wrote:
> Hi,
>
> The Go presentations with embedded code are done using the Go present
> package [1]. It supports running code (i.e. playground) out of the box, but
> for Go only. Adding additional language support is quite easy, only about 10
> lines of code, but you won't find help on this mailing list doing it :D
> (sorry, Gophers tend to stick to their toys :D). But if you'll search the
> mailing list archives, you'll find my post of about half a year ago with
> running Erlang inside Go present :P.
>
> Cheers,
> Peter
>
> [1]
http://godoc.org/code.google.com/p/go.tools/present
Hi,
Thanks for the response. I'm using Go 1.1 and checked out `present`
today. It was hard to believe but `present` supports scripted
languages (the ones whose first line starts with a shebang) out of the
box! Awesome. It is implemented in the file
`
code.google.com/p/go.tools/playground/socket/socket.go`. There is a
function called `shebang()` that checks the first line. However, I
found a bug in `shebang()`. The last line should be `return fs[0], fs`
instead of `return fs[0], fs[1:]`. (I reported the issue here:
http://code.google.com/p/go/issues/detail?id=7321).
Now, if you want to use Python code snippets, just write this in the
presentation (example):
* Hello Py
.play hello.py
Where the source of hello.py is:
#!/usr/bin/env python -u
# encoding: utf-8
from __future__ import print_function
from time import sleep
while True:
print("Hello, Py!")
sleep(1)
(The switch -u means unbuffered output. Without this you wouldn't see
any output while the `print` calls in the loop are buffered.)
Sorry for the Python post but I think there are lots of Pythonistas
who also use Go :) And thanks for the authors of `present` who thought
of script languages too.
Laszlo