Skip to content

Instantly share code, notes, and snippets.

@wookay
Created September 23, 2011 06:37
Show Gist options
  • Save wookay/1236861 to your computer and use it in GitHub Desktop.
Save wookay/1236861 to your computer and use it in GitHub Desktop.
auto refresh moai main.lua
#! /usr/bin/ruby
# run_moai.rb
# wookay.noh at gmail.com
# sudo gem install filewatcher
require 'rubygems'
require 'filewatcher'
WatchFiles = []
WATCH_PATTERN = /.lua$/
require 'find'
Find.find('.') do |filename|
if filename =~ WATCH_PATTERN
path = Dir.pwd + filename[1..-1]
WatchFiles.push path
end
end
$main_lua = 'main.lua'
$job = nil
def kill_previous_job
if nil == $job
else
Process.kill("HUP", $job)
end
end
def run_main
kill_previous_job
$job = fork do
exec "moai #{$main_lua}"
end
Process.detach($job)
end
if ARGV.to_s == ''
else
$main_lua = ARGV.to_s
end
run_main
FileWatcher.new(WatchFiles).watch(0.5) do |filename|
puts "Updated " + filename
run_main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment