1. global LF
  2. global cx
  3.  
  4. ----------------------------------------
  5. --
  6. ----------------------------------------
  7. on startMovie
  8.     _movie.stage.rect = rect(0, 0, 320, 240).offset(20, 34)
  9.     cx = xtra("console").new()
  10.  
  11.     LF = numToChar(10)
  12.     x = 70
  13.     w = 180
  14.     sn = 1
  15.     y = 10
  16.     dy = 30
  17.  
  18.     m = new(#button)
  19.     m.rect = rect(0, 0, w, 0)
  20.     m.alignment = "center"
  21.     m.text = "Print to StdOut (green)"
  22.     m.scriptText = "on mouseUp"&RETURN&"testStdOut()"&RETURN&"end"
  23.     _movie.puppetSprite(sn, TRUE)
  24.     sprite(sn).member = m
  25.     sprite(sn).loc = point(x, y)
  26.     y = y + dy
  27.     sn = sn + 1
  28.  
  29.     m = new(#button)
  30.     m.rect = rect(0, 0, w, 0)
  31.     m.alignment = "center"
  32.     m.text = "Print to StdErr (red)"
  33.     m.scriptText = "on mouseUp"&RETURN&"testStdErr()"&RETURN&"end"
  34.     _movie.puppetSprite(sn, TRUE)
  35.     sprite(sn).member = m
  36.     sprite(sn).loc = point(x, y)
  37.     y = y + dy
  38.     sn = sn + 1
  39.  
  40.     m = new(#button)
  41.     m.rect = rect(0, 0, w, 0)
  42.     m.alignment = "center"
  43.     m.text = "Test stdIn input (blocking!)"
  44.     m.scriptText = "on mouseUp"&RETURN&"testStdIn()"&RETURN&"end"
  45.     _movie.puppetSprite(sn, TRUE)
  46.     sprite(sn).member = m
  47.     sprite(sn).loc = point(x, y)
  48.     y = y + dy
  49.     sn = sn + 1
  50.  
  51.     m = new(#button)
  52.     m.rect = rect(0, 0, w, 0)
  53.     m.alignment = "center"
  54.     m.text = "Trigger script error"
  55.     m.scriptText = "on mouseUp"&RETURN&"x = 1/0"&RETURN&"end"
  56.     _movie.puppetSprite(sn, TRUE)
  57.     sprite(sn).member = m
  58.     sprite(sn).loc = point(x, y)
  59.     y = y + dy
  60.     sn = sn + 1
  61.  
  62.     m = new(#button)
  63.     m.rect = rect(0, 0, w, 0)
  64.     m.alignment = "center"
  65.     m.text = "Change console font"
  66.     m.scriptText = "on mouseUp"&RETURN&"testFont()"&RETURN&"end"
  67.     _movie.puppetSprite(sn, TRUE)
  68.     sprite(sn).member = m
  69.     sprite(sn).loc = point(x, y)
  70.     y = y + dy
  71.     sn = sn + 1
  72.  
  73.     m = new(#button)
  74.     m.rect = rect(0, 0, w, 0)
  75.     m.alignment = "center"
  76.     m.text = "Clear console window"
  77.     m.scriptText = "on mouseUp"&RETURN&"_global.cx.consoleClear()"&RETURN&"end"
  78.     _movie.puppetSprite(sn, TRUE)
  79.     sprite(sn).member = m
  80.     sprite(sn).loc = point(x, y)
  81.     y = y + dy
  82.     sn = sn + 1
  83.  
  84.     m = new(#button)
  85.     m.rect = rect(0, 0, w, 0)
  86.     m.alignment = "center"
  87.     m.text = "Start REPL" & RETURN & "(interactive input-output loop)"
  88.     m.scriptText = "on mouseUp"&RETURN&"testRepl()"&RETURN&"end"
  89.     _movie.puppetSprite(sn, TRUE)
  90.     sprite(sn).member = m
  91.     sprite(sn).loc = point(x, y)
  92.     y = y + dy
  93.     sn = sn + 1
  94.  
  95.     _movie.updateStage()
  96.  
  97.     if cx.consoleExists() then
  98.         -- if the projector was started in a console, attach this console
  99.         cx.consoleAttach()
  100.     else
  101.         -- otherwise create a new console window
  102.         cx.consoleCreate()
  103.     end if
  104.  
  105.     -- change console title (optional)
  106.     cx.consoleSetTitle("Fancy Lingo Console")
  107.  
  108.     -- Windows console color constants
  109.     FOREGROUND_BLUE = 1
  110.     FOREGROUND_GREEN = 2
  111.     FOREGROUND_RED = 4
  112.     FOREGROUND_INTENSITY = 8 -- Foreground color is intensified.
  113.     BACKGROUND_BLUE = 16
  114.     BACKGROUND_GREEN = 32
  115.     BACKGROUND_RED = 64
  116.     BACKGROUND_INTENSITY = 128 -- Background color is intensified.
  117.  
  118.     -- set colors (optional)
  119.     stdinCol  = FOREGROUND_RED + FOREGROUND_GREEN + FOREGROUND_INTENSITY
  120.     stdoutCol = FOREGROUND_GREEN + FOREGROUND_INTENSITY
  121.     stderrCol = FOREGROUND_RED + FOREGROUND_INTENSITY
  122.     cx.consoleSetColors(stdinCol, stdoutCol, stderrCol)
  123.  
  124.     _player.alertHook = _movie
  125. end
  126.  
  127. ----------------------------------------
  128. --
  129. ----------------------------------------
  130. on stopMovie
  131.     cx.consoleClose()
  132. end
  133.  
  134. ----------------------------------------
  135. -- alertHook that prints scripting errors as stdErr to console
  136. ----------------------------------------
  137. on alertHook (aMsg, aText, aType)
  138.     case (aType) of
  139.     #alert:
  140.         return 0
  141.     otherwise:
  142.         cx.stdOut("") -- force flush
  143.         sleep(50)
  144.         cx.stdErr(aMsg & ": " & aText & LF)
  145.         return 1
  146.     end case
  147. end
  148.  
  149. ----------------------------------------
  150. --
  151. ----------------------------------------
  152. on testStdOut
  153.     cx.stdOut("Hello world!" & LF)
  154. end
  155.  
  156. ----------------------------------------
  157. --
  158. ----------------------------------------
  159. on testStdErr
  160.     cx.stdErr("This is an error!" & LF)
  161. end
  162.  
  163. ----------------------------------------
  164. --
  165. ----------------------------------------
  166. on testStdIn
  167.     res = cx.stdIn("Please enter your name (+ENTER key): ")
  168.     cx.stdOut("Your name is: " & res & LF)
  169. end
  170.  
  171. ----------------------------------------
  172. --
  173. ----------------------------------------
  174. on testFont
  175.     cx.consoleSetFont("Consolas", 28)
  176. end
  177.  
  178. ----------------------------------------
  179. --
  180. ----------------------------------------
  181. on testRepl
  182.     cx.consoleSetInputCallback(#consoleInputCallback)
  183.     cx.stdOut("Type something (and hit ENTER key)." & LF)
  184.     cx.stdOut("> ")
  185. end
  186.  
  187. ----------------------------------------
  188. --
  189. ----------------------------------------
  190. on consoleInputCallback (str)
  191.     cx.stdOut("Your entered: " & str & LF)
  192.     cx.stdOut("> ")
  193. end
  194.  
[raw code]