Skip to content

Commit

Permalink
map over scripts & lines in interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermg committed Apr 5, 2015
1 parent cb536c1 commit 4ff45e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 5 additions & 2 deletions public/js/interpreter.coffee
Original file line number Diff line number Diff line change
@@ -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}"

20 changes: 16 additions & 4 deletions public/js/scriptloader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 4ff45e3

Please sign in to comment.