yglukhov / nimx

GUI library
MIT License
1.1k stars 75 forks source link

accessing local variables periodically #182

Closed ghost closed 8 years ago

ghost commented 8 years ago

If indeed it's not possible, then some ways to deal with this includes:

yglukhov commented 8 years ago

Looks like you wanted to post this elsewhere, because I could not understand a thing.

ghost commented 8 years ago

No, this is the correct repo 😆

What I meant was, is there a way to execute user code periodically, which accesses some state that is not declared globally? The callback passed to timers.setInterval neither takes a parameter nor is it a closure. The first bullet point might be the wrong approach, because I'm not sure how that would translate to browser applications for example.

Does it make sense now?

yglukhov commented 8 years ago

timers.setInterval takes a closure as argument.

var i = 0
setInterval(1.0) do():
  inc i
  echo i
ghost commented 8 years ago

I thought it was necessary to annotate the parameter with the closure pragma. Won't the function where setInterval is invoked go out of scope before the event loop is executed?

yglukhov commented 8 years ago

I thought it was necessary to annotate the parameter with the closure pragma.

Proc args are closures by default.

Won't the function where setInterval is invoked go out of scope before the event loop is executed?

Sorry, but I don't understand the question again. setInterval schedules a timer in runloop. Why would scope matter?

ghost commented 8 years ago

nevermind