summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLieuwe <lieuwemo@gmail.com>2011-02-26 19:50:06 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-03-02 20:54:30 (GMT)
commit448d5982fa7f700e2a69d24618227d52ecbb35a1 (patch)
tree8a6c6eaeeb5f3de57e83835ced17e01bd8eca7d7
parente1face5735b079352aa6d0e22d2ab18bade12bbc (diff)
downloadpowder-448d5982fa7f700e2a69d24618227d52ecbb35a1.zip
powder-448d5982fa7f700e2a69d24618227d52ecbb35a1.tar.gz
broke a lot of stuff. semi-fixed the console itself.
-rw-r--r--build/example.py5
-rw-r--r--build/tpt_console.py46
2 files changed, 11 insertions, 40 deletions
diff --git a/build/example.py b/build/example.py
index b1ac778..3bde517 100644
--- a/build/example.py
+++ b/build/example.py
@@ -1,11 +1,10 @@
import tpt
import random
+import time
# example script
def noise(typ,amount=50):
for xx in range(284,316):
for yy in range(184,216):
if(random.randrange(0,100)<amount):
- tpt.create(xx,yy,typ)
-
-
+ tpt.create(xx,yy,typ) \ No newline at end of file
diff --git a/build/tpt_console.py b/build/tpt_console.py
index c11d3e7..16c20c9 100644
--- a/build/tpt_console.py
+++ b/build/tpt_console.py
@@ -5,12 +5,12 @@ import ctypes
import traceback
from threading import Thread
print "console module loaded."
-"""#redirect stdout like this:
+#redirect stdout like this:
class logger:
def write(self,txt):
- txt=txt[:254]
+ txt=txt.split("\n")[-1][:254]
tpt.log(txt)
-sys.stdout=logger()"""
+#sys.stdout=logger()
element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7,
"nitr":8,"clne":9,"gas":10,"plex":11,"goo":12,"icei":13,"metl":14,"sprk":15,
@@ -36,19 +36,6 @@ element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7,
"lote":142,"frg2":143,"star":144,"frog":145,"bran":146,"wind":147,
"num":148}
-def _async_raise(tid, exctype):
- '''Raises an exception in the threads with id tid'''
- if not inspect.isclass(exctype):
- raise TypeError("Only types can be raised (not instances)")
- res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
- if res == 0:
- raise ValueError("invalid thread id")
- elif res != 1:
- # """if it returns a number greater than one, you're in trouble,
- # and you should call it again with exc=NULL to revert the effect"""
- ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
- raise SystemError("PyThreadState_SetAsyncExc failed")
-
class _fork(Thread):
def __init__ (self,func):
Thread.__init__(self)
@@ -65,6 +52,7 @@ def fork(func):
fork.threads[fork.i]=tmp
fork.i+=1
tmp.start()
+ return tmp
tpt.log("Thread #%d started"%(fork.i-1))
def fork_status():
count=0
@@ -86,7 +74,7 @@ def error(ex):
def clean():
#add any functions that must be reachable here.
copy=["__builtins__","__name__","__doc__","__package__",'tpt','clean',
- 'element','fork','_fork','fork_status','fork_unblock']
+ 'element','fork','_fork','fork_status','fork_unblock','sys']
handle.glob={}
for item in copy:
handle.glob[item]=globals()[item]
@@ -104,27 +92,11 @@ def handle(txt):
traceback.print_exc()
def _handle(txt):
- print "handling '%s'"%txt
- tpt.console_less()
- try:
- #tmp=code.compile_command('\n'.join(handle.txt))
- tmp=code.compile_command(txt)
- except Exception as ex:
- #tpt.log("Invalid code. see stdout for more info.")
- error(ex)
- print "### -------------------- trace"
- traceback.print_exc()
- return
- if(tmp==None):
+ #print "handling '%s'"%txt
+ exec txt in handle.glob
+ if(False):
tpt.console_more()
else:
- try:
- #print "executing"
- exec tmp in handle.glob
- except Exception as ex:
- #tpt.log("Invalid code. see stdout for more info.")
- error(ex)
- print "### -------------------- trace"
- traceback.print_exc()
+ tpt.console_less()
\ No newline at end of file