annotate code.py @ 183:7b6aba7839ea

getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary. This WILL break old saves.
author Beliar <KarstenBock@gmx.net>
date Thu, 15 Mar 2012 16:24:05 +0100
parents
children
rev   line source
183
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
1 """Utilities needed to emulate Python's interactive interpreter with changes for PARPG
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
2 The original code module is part of pythons standard modules.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
3 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
4
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
5 # Inspired by similar code by Jeff Epler and Fredrik Lundh.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
6
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
7 # Changed for PARPG to also accept a globals argument
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
8
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
9 import sys
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
10 import traceback
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
11 from codeop import CommandCompiler, compile_command
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
12
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
13 __all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
14 "compile_command"]
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
15
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
16 def softspace(file, newvalue):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
17 oldvalue = 0
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
18 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
19 oldvalue = file.softspace
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
20 except AttributeError:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
21 pass
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
22 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
23 file.softspace = newvalue
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
24 except (AttributeError, TypeError):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
25 # "attribute-less object" or "read-only attributes"
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
26 pass
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
27 return oldvalue
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
28
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
29 class InteractiveInterpreter:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
30 """Base class for InteractiveConsole.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
31
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
32 This class deals with parsing and interpreter state (the user's
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
33 namespace); it doesn't deal with input buffering or prompting or
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
34 input file naming (the filename is always passed in explicitly).
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
35
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
36 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
37
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
38 def __init__(self, globals=None, locals=None ):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
39 """Constructor.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
40
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
41 The optional 'globals' and 'locals' arguments specify the dictionary in
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
42 which code will be executed; globals defaults to a newly created
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
43 dictionary with key "__name__" set to "__console__" and key
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
44 "__doc__" set to None.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
45
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
46 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
47 if globals is None:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
48 globals = {"__name__": "__console__", "__doc__": None}
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
49 self.locals = locals
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
50 self.globals = globals
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
51 self.compile = CommandCompiler()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
52
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
53 def runsource(self, source, filename="<input>", symbol="single"):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
54 """Compile and run some source in the interpreter.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
55
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
56 Arguments are as for compile_command().
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
57
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
58 One several things can happen:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
59
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
60 1) The input is incorrect; compile_command() raised an
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
61 exception (SyntaxError or OverflowError). A syntax traceback
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
62 will be printed by calling the showsyntaxerror() method.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
63
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
64 2) The input is incomplete, and more input is required;
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
65 compile_command() returned None. Nothing happens.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
66
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
67 3) The input is complete; compile_command() returned a code
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
68 object. The code is executed by calling self.runcode() (which
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
69 also handles run-time exceptions, except for SystemExit).
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
70
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
71 The return value is True in case 2, False in the other cases (unless
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
72 an exception is raised). The return value can be used to
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
73 decide whether to use sys.ps1 or sys.ps2 to prompt the next
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
74 line.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
75
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
76 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
77 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
78 code = self.compile(source, filename, symbol)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
79 except (OverflowError, SyntaxError, ValueError):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
80 # Case 1
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
81 self.showsyntaxerror(filename)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
82 return False
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
83
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
84 if code is None:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
85 # Case 2
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
86 return True
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
87
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
88 # Case 3
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
89 self.runcode(code)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
90 return False
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
91
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
92 def runcode(self, code):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
93 """Execute a code object.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
94
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
95 When an exception occurs, self.showtraceback() is called to
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
96 display a traceback. All exceptions are caught except
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
97 SystemExit, which is reraised.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
98
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
99 A note about KeyboardInterrupt: this exception may occur
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
100 elsewhere in this code, and may not always be caught. The
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
101 caller should be prepared to deal with it.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
102
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
103 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
104 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
105 exec code in self.globals, self.locals
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
106 except SystemExit:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
107 raise
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
108 except:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
109 self.showtraceback()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
110 else:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
111 if softspace(sys.stdout, 0):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
112 print
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
113
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
114 def showsyntaxerror(self, filename=None):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
115 """Display the syntax error that just occurred.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
116
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
117 This doesn't display a stack trace because there isn't one.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
118
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
119 If a filename is given, it is stuffed in the exception instead
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
120 of what was there before (because Python's parser always uses
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
121 "<string>" when reading from a string).
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
122
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
123 The output is written by self.write(), below.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
124
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
125 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
126 type, value, sys.last_traceback = sys.exc_info()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
127 sys.last_type = type
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
128 sys.last_value = value
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
129 if filename and type is SyntaxError:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
130 # Work hard to stuff the correct filename in the exception
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
131 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
132 msg, (dummy_filename, lineno, offset, line) = value
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
133 except:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
134 # Not the format we expect; leave it alone
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
135 pass
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
136 else:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
137 # Stuff in the right filename
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
138 value = SyntaxError(msg, (filename, lineno, offset, line))
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
139 sys.last_value = value
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
140 list = traceback.format_exception_only(type, value)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
141 map(self.write, list)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
142
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
143 def showtraceback(self):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
144 """Display the exception that just occurred.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
145
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
146 We remove the first stack item because it is our own code.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
147
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
148 The output is written by self.write(), below.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
149
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
150 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
151 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
152 type, value, tb = sys.exc_info()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
153 sys.last_type = type
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
154 sys.last_value = value
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
155 sys.last_traceback = tb
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
156 tblist = traceback.extract_tb(tb)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
157 del tblist[:1]
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
158 list = traceback.format_list(tblist)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
159 if list:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
160 list.insert(0, "Traceback (most recent call last):\n")
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
161 list[len(list):] = traceback.format_exception_only(type, value)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
162 finally:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
163 tblist = tb = None
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
164 map(self.write, list)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
165
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
166 def write(self, data):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
167 """Write a string.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
168
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
169 The base implementation writes to sys.stderr; a subclass may
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
170 replace this with a different implementation.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
171
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
172 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
173 sys.stderr.write(data)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
174
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
175
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
176 class InteractiveConsole(InteractiveInterpreter):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
177 """Closely emulate the behavior of the interactive Python interpreter.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
178
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
179 This class builds on InteractiveInterpreter and adds prompting
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
180 using the familiar sys.ps1 and sys.ps2, and input buffering.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
181
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
182 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
183
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
184 def __init__(self, globals=None, locals=None, filename="<console>"):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
185 """Constructor.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
186
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
187 The optional locals and globals argument swill be passed to the
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
188 InteractiveInterpreter base class.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
189
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
190 The optional filename argument should specify the (file)name
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
191 of the input stream; it will show up in tracebacks.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
192
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
193 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
194 InteractiveInterpreter.__init__(self, globals, locals)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
195 self.filename = filename
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
196 self.resetbuffer()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
197
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
198 def resetbuffer(self):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
199 """Reset the input buffer."""
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
200 self.buffer = []
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
201
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
202 def interact(self, banner=None):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
203 """Closely emulate the interactive Python console.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
204
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
205 The optional banner argument specify the banner to print
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
206 before the first interaction; by default it prints a banner
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
207 similar to the one printed by the real Python interpreter,
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
208 followed by the current class name in parentheses (so as not
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
209 to confuse this with the real interpreter -- since it's so
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
210 close!).
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
211
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
212 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
213 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
214 sys.ps1
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
215 except AttributeError:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
216 sys.ps1 = ">>> "
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
217 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
218 sys.ps2
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
219 except AttributeError:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
220 sys.ps2 = "... "
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
221 cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
222 if banner is None:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
223 self.write("Python %s on %s\n%s\n(%s)\n" %
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
224 (sys.version, sys.platform, cprt,
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
225 self.__class__.__name__))
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
226 else:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
227 self.write("%s\n" % str(banner))
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
228 more = 0
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
229 while 1:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
230 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
231 if more:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
232 prompt = sys.ps2
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
233 else:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
234 prompt = sys.ps1
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
235 try:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
236 line = self.raw_input(prompt)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
237 # Can be None if sys.stdin was redefined
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
238 encoding = getattr(sys.stdin, "encoding", None)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
239 if encoding and not isinstance(line, unicode):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
240 line = line.decode(encoding)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
241 except EOFError:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
242 self.write("\n")
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
243 break
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
244 else:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
245 more = self.push(line)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
246 except KeyboardInterrupt:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
247 self.write("\nKeyboardInterrupt\n")
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
248 self.resetbuffer()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
249 more = 0
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
250
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
251 def push(self, line):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
252 """Push a line to the interpreter.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
253
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
254 The line should not have a trailing newline; it may have
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
255 internal newlines. The line is appended to a buffer and the
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
256 interpreter's runsource() method is called with the
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
257 concatenated contents of the buffer as source. If this
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
258 indicates that the command was executed or invalid, the buffer
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
259 is reset; otherwise, the command is incomplete, and the buffer
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
260 is left as it was after the line was appended. The return
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
261 value is 1 if more input is required, 0 if the line was dealt
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
262 with in some way (this is the same as runsource()).
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
263
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
264 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
265 self.buffer.append(line)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
266 source = "\n".join(self.buffer)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
267 more = self.runsource(source, self.filename)
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
268 if not more:
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
269 self.resetbuffer()
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
270 return more
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
271
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
272 def raw_input(self, prompt=""):
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
273 """Write a prompt and read a line.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
274
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
275 The returned line does not include the trailing newline.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
276 When the user enters the EOF key sequence, EOFError is raised.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
277
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
278 The base implementation uses the built-in function
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
279 raw_input(); a subclass may replace this with a different
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
280 implementation.
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
281
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
282 """
7b6aba7839ea getGameEnvironment of GameState now returns a locals dictionary that is empty at the beginning of the game and will be saved in save games. The vals and funcs are now both in the globals dictionary.
Beliar <KarstenBock@gmx.net>
parents:
diff changeset
283 return raw_input(prompt)