Smallest ChucK IDE Ever

From CSWiki
Jump to: navigation, search

this python script calls the SciTE editor to edit a ChucK script given on the command line and runs the ChucK script as well. Whenever the file is saved, the ChucK VM is stopped and rerun. When there is a syntax error it is being displayed and runchuck.py waits until the file is saved again.

runchuck.py:

#!/usr/bin/python

import os,stat,time,sys,signal

if len(sys.argv) > 1:
        os.system("scite " + sys.argv[1] + " &")
        #pid = os.spawnl(os.P_NOWAIT,"/usr/bin/scite","/usr/bin/scite",sys.argv[1])
        while 1:
                print "starting..."
                mtime = os.stat(sys.argv[1])[stat.ST_MTIME]
                pid = os.spawnl(os.P_NOWAIT,"/usr/bin/chuck","/usr/bin/chuck","--srate48000",sys.argv[1])
                print pid
                while 1:
                        try:
                                os.waitpid(pid,os.WNOHANG)
                        except:
                                pid = 0
                        nmtime = os.stat(sys.argv[1])[stat.ST_MTIME]
                        if nmtime != mtime:
                                mtime = nmtime
                                print "script changed..."
                                break
                        time.sleep(0.25)
                if pid:
                        os.kill(pid,signal.SIGKILL)
                        os.waitpid(pid,0)
else:
        print "usage: runchuck.py <chuckscript>"