aroberge / reeborg

Enhanced Karel-the-robot clone
http://reeborg.ca/reeborg.html
Other
47 stars 36 forks source link

Check for post code #377

Closed aroberge closed 6 years ago

aroberge commented 6 years ago

Currently, if code is included in the Post editor, a world creator has to explicitly disable done() to prevent a user from having a program bypass the Post editor. However, if the user's code include

from library import *

done() is likely going to be redefined to its basic value.

What should be done is the following

  1. Check if Post editor contains code
  2. if so, instead of doing Pre + Editor + Post, one should do something like Pre + Editor + RUR.confirm_post() + Post which would set up a flag.
  3. When evaluating success or failure, check again to see if Post code is present; if so, confirm that the Post code has run.

If Post code is present but not executed, an error message should be displayed, something like "This world included some code which was meant to run after the user's program but which has been prevented from running."

Make sure that this works for done() when used at the REPL.

aroberge commented 6 years ago

This issue, as described, is no longer needed: in https://github.com/aroberge/reeborg/blob/master/src/python/common.py, where the Python code gets executed, I have added the following:

    if window.RUR.state.done_executed:
        try:
            exec(post_code, globals_)
        except Exception as e:
            window.RUR.__python_error = e