require 'fssm'
require 'osc'
# Host = '192.168.1.67'
# Host = '192.168.1.182'
Host = 'localhost'
Port = 9001
c = OSC::UDPSocket.new

FSSM.monitor(Dir.pwd, '**/*.lua') do
  update {|base, relative|
    File.open(relative, "r"){|aFile|
      s = aFile.read
      if s.lines.count < 80 then
      	m = OSC::Message.new('/eval', 'sf', s, 0.1)
      else
      	m = OSC::Message.new('/eval', 'sf', "print('too long')", 0.1)
      end
      c.send m, 0, Host, Port
    }
  }
  delete {|base, relative|}
  create {|base, relative|}
end
