1

I'm trying to make a "compiler" for my game (so that people could do intresting stuff but not inject code), for mainly declaritive "code" (It would look like this: {"player_location":"IceHall.A7", "print", "You are teleported somewhere", "tiles":{"FirePlace.B3":{'Type':"Corner", "Actions+":{....}}}}. This is how a action is represented; It is called when the player does it. Anyways, it would have to be compiled into a function. When I tryed out something similar in the interactive interpreter (specifically:

def compile(code):
    def act():
       exec code
    return act

). This (which is would be more or less what would be in the final, with the exception of "code" being constructed by me) raised a odd error:

File "", line 3 SyntaxError:
unqualified exec is not allowed in function 'act' it is a nested function.

How do I get around this?

Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
technillogue
  • 1,302
  • 3
  • 14
  • 27

1 Answers1

0

The answer, as said in this question, is the lack of context. I wanted exec code in locals(), globals()

Community
  • 1
  • 1
technillogue
  • 1,302
  • 3
  • 14
  • 27