· 8 years ago · Jan 21, 2018, 01:10 PM
1#! /usr/bin/ruby
2
3# run_moai.rb
4# wookay.noh at gmail.com
5
6
7# sudo gem install filewatcher
8
9require 'rubygems'
10require 'filewatcher'
11
12WatchFiles = []
13WATCH_PATTERN = /.lua$/
14require 'find'
15Find.find('.') do |filename|
16 if filename =~ WATCH_PATTERN
17 path = Dir.pwd + filename[1..-1]
18 WatchFiles.push path
19 end
20end
21
22
23$main_lua = 'main.lua'
24
25$job = nil
26def kill_previous_job
27 if nil == $job
28 else
29 Process.kill("HUP", $job)
30 end
31end
32def run_main
33 kill_previous_job
34 $job = fork do
35 exec "moai #{$main_lua}"
36 end
37 Process.detach($job)
38end
39
40if ARGV.to_s == ''
41else
42 $main_lua = ARGV.to_s
43end
44
45run_main
46
47FileWatcher.new(WatchFiles).watch(0.5) do |filename|
48 puts "Updated " + filename
49 run_main
50end