Re: [code] [textadept] Textadept 10.0 alpha issue II

From: Michal Kottman <k0mpjut0r.att.gmail.com>
Date: Tue, 9 Jan 2018 21:07:10 +0100

On Jan 9, 2018 20:29, "Gabriel Dubatti" <gdubatti.att.gmail.com> wrote:

function log_event(event)
  local line= os.date('%c')..": "..event.."\n"
  log_ev[#log_ev+1]= line
end

log_event("INIT_START")

events.connect(events.RESET_BEFORE, log_event("RESET_BEFORE"))
events.connect(events.RESET_AFTER, log_event("RESET_AFTER"))
events.connect(events.INITIALIZED, log_event("INITIALIZED"))
events.connect(events.BUFFER_NEW, log_event("BUFFER_NEW"))

keys.cf4 = reset

keys.cf5 = function()
  buffer.new()
  for i=1,#log_ev do
    buffer:append_text(log_ev[i])
  end
  buffer:set_save_point()
end

log_event("INIT_END")
------------------

And get the following output (press Ctrl+F5 to show):
........................
mar 09 ene 2018 16:10:31 -03: INIT_START
mar 09 ene 2018 16:10:31 -03: RESET_BEFORE
mar 09 ene 2018 16:10:31 -03: RESET_AFTER
mar 09 ene 2018 16:10:31 -03: INITIALIZED
mar 09 ene 2018 16:10:31 -03: BUFFER_NEW
mar 09 ene 2018 16:10:31 -03: INIT_END
....................

Why does the INITIALIZED event appear before "INIT_END" ?

You are actually executing the "log_event" calls as you setup the events
instead of registering callbacks. Try this:

events.connect(events.RESET_BEFORE, function() log_event("RESET_BEFORE")
end)
...

Or:

function log_event_callback(name)
  return function() log_event(name) end
end
...
events.connect(events.RESET_BEFORE, log_event_callback("RESET_BEFORE"))

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Tue 09 Jan 2018 - 15:07:10 EST

This archive was generated by hypermail 2.2.0 : Wed 10 Jan 2018 - 06:34:22 EST