Brainfuck: Add --recover.
parent
ca2ad15335
commit
b5afe0f832
|
@ -127,6 +127,7 @@ class Brainfuck(callbacks.Plugin):
|
|||
"""Add the help for "@plugin help Brainfuck" here
|
||||
This should describe *how* to use this plugin."""
|
||||
threaded = True
|
||||
latestProcessor = None
|
||||
|
||||
@internationalizeDocstring
|
||||
def checksyntax(self, irc, msg, args, code):
|
||||
|
@ -145,15 +146,26 @@ class Brainfuck(callbacks.Plugin):
|
|||
|
||||
@internationalizeDocstring
|
||||
def brainfuck(self, irc, msg, args, opts, code):
|
||||
"""[--input <characters>] <command>
|
||||
"""[--recover] [--input <characters>] <command>
|
||||
|
||||
Interprets the given Brainfuck code. You should quote the code if you
|
||||
use brackets, because Supybot would interpret it as nested commands.
|
||||
If --recover is given, the bot will recover the previous processor
|
||||
memory and memory pointer.
|
||||
The code will be fed the <characters> when it asks for input."""
|
||||
opts = dict(opts)
|
||||
if 'input' not in opts:
|
||||
opts['input'] = ''
|
||||
processor = BrainfuckProcessor()
|
||||
if 'recover' in opts:
|
||||
if self.latestProcessor is None:
|
||||
irc.error(_('No processor has been run for the moment.'))
|
||||
return
|
||||
else:
|
||||
processor = self.latestProcessor
|
||||
else:
|
||||
processor = BrainfuckProcessor()
|
||||
self.latestProcessor = processor
|
||||
|
||||
try:
|
||||
output = processor.execute(code, input_=opts['input'])
|
||||
except BrainfuckSyntaxError as e:
|
||||
|
@ -166,7 +178,9 @@ class Brainfuck(callbacks.Plugin):
|
|||
irc.error(_('Input too short.'))
|
||||
return
|
||||
irc.reply(output)
|
||||
brainfuck = wrap(brainfuck, [getopts({'input': 'something'}), 'text'])
|
||||
brainfuck = wrap(brainfuck, [getopts({'recover': '',
|
||||
'input': 'something'}),
|
||||
'text'])
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -62,5 +62,11 @@ class BrainfuckTestCase(PluginTestCase):
|
|||
self.assertRegexp('brainfuck "[[]]]"',
|
||||
'Error: Brainfuck syntax error: .*whatever.*')
|
||||
|
||||
def testRecover(self):
|
||||
self.assertNotError('brainfuck --input a ,.')
|
||||
self.assertResponse('brainfuck .', "'\\x00'")
|
||||
self.assertNotError('brainfuck --input a ,.')
|
||||
self.assertResponse('brainfuck --recover .', 'a')
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
|
Loading…
Reference in New Issue