From 4ff45e3cb52864914c6482abd94e2c1bdef3b302 Mon Sep 17 00:00:00 2001 From: Oliver Wegner Date: Sun, 5 Apr 2015 13:59:02 +0200 Subject: [PATCH] map over scripts & lines in interpreter --- public/js/interpreter.coffee | 7 +++++-- public/js/scriptloader.coffee | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/public/js/interpreter.coffee b/public/js/interpreter.coffee index 78e557a..54263cf 100644 --- a/public/js/interpreter.coffee +++ b/public/js/interpreter.coffee @@ -1,4 +1,7 @@ -return () -> - console.log 'wurst interpreter' +return (scripts) -> + console.log "got scripts: #{scripts}" + scripts.map (script) -> + script.map (line) -> + console.log "interpreting #{line}" diff --git a/public/js/scriptloader.coffee b/public/js/scriptloader.coffee index dcea44e..3314a89 100644 --- a/public/js/scriptloader.coffee +++ b/public/js/scriptloader.coffee @@ -5,18 +5,30 @@ class Scriptloader $.ajax { url: "/js/#{interpreter}", dataType: 'text', # setting it to 'script' would automatically invoke it - success: (data) => # => binds 'this' inside function to instance of Scriptloader + success: (data) => # '=>' binds 'this' inside function to instance of Scriptloader @interpreter = eval data if onready - onready.call this, @interpreter # call of instance var binds 'this' to instance of Scriptloader + onready.call this # call of instance var binds 'this' to instance of Scriptloader error: (xhr, stuff, error) -> console.log "ERROR loading interpreter: #{error}" } run: () => - @interpreter(@scripts) + @interpreter @scripts -@scriptloader = new Scriptloader 'interpreter.js', [], () -> +scripts = [ + [ + "1:aaa", + "1:bbb" + ], + [ + "2:aaa", + "2:bbb", + "3:ccc" + ] +] + +@scriptloader = new Scriptloader 'interpreter.js', scripts, () -> console.log 'before' @run() console.log 'after'