Skip to content

Instantly share code, notes, and snippets.

@xcombelle
Last active September 9, 2016 20:34
Show Gist options
  • Select an option

  • Save xcombelle/991cf764ddeaf77ba08c3c27880169bf to your computer and use it in GitHub Desktop.

Select an option

Save xcombelle/991cf764ddeaf77ba08c3c27880169bf to your computer and use it in GitHub Desktop.
bootstrapping egg-drop
# the idea of the bootstrap proc is that it delegate
# the creation of the dialog between tcl and python
# to the python script so all the protocol always match
# between tcl and python
proc bootstrap {scriptname args} {
set fifo_name /tmp/eggdrop-bootstrap-fifo
set interpreter python3
exec mkfifo $fifo_name
try {
set command [
concat [list exec $interpreter $scriptname "--eggdrop-bootstrap-fifo=$fifo_name"] $args
]
puts $command
eval $command
set fp [open $fifo_name r]
#here is the magic to delegate the protocol creation to the python script
eval [read $fp]
close $fp
} finally {
exec rm $fifo_name
}
}
#usage
bootstrap test.py dummy-arg1 dummy-arg2
@dereckson
Copy link
Copy Markdown

I wonder if a pipe shouldn't be abstracted, as some people compile with Cygwin eggdrops to run them on Windows (see http://windrop.sourceforge.net/). We don't need to implement that, but a little abstraction will allow interested people to do it.

concat list is perhaps overkill in this scenario: perhaps this syntax would be more legible (and would avoid an eval):
exec -- $interpreter $scriptname "--eggdrop-bootstrap-fifo=$fifo_name" {*}$args

Per try finally, we will need to document we target TCL 8.6+ (a reasonable requirement)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment