为什么我的 Ruby 脚本无法在 TextMate 中执行?
我正在学习使用 Ruby 和 Gosu 的基本游戏编程。我已经从 RubyGems 安装了 Gosu,它当前位于 /usr/local/lib/ruby/gems/1.9.1/gems/
中。
完整路径为 /usr/local/lib/ruby/gems/1.9.1/gems/gosu-0.7.24-universal-darwin/
。
当我处理游戏脚本时,我可以使用终端命令 ruby game.rb
很好地执行该文件。但是,当我在 TextMate 中编辑脚本并尝试使用 command-R 执行脚本时,标准执行窗口会出现,但除了旋转的进度指示器之外什么也不做。
我已将 gosu-9.7.24-universal-darwin/
的所有者更改为自己,甚至尝试更改整个 ruby/
目录的所有者 (/ usr/local/lib/ruby/
),但无济于事。
我在 TextMate 中使用标准 Ruby 包。
这是我尝试运行的脚本,但任何示例脚本上都会发生相同的事件:
require "rubygems"
require "gosu"
class GameWindow < Gosu::Window
def initialize
super(640,360, false)
self.caption = "Gosu Tutorial Game"
end
def update
end
def draw
end
def button_down(id)
if id == Gosu::KbEscape
close
end
end
end
window = GameWindow.new
window.show
更新
根据 Greg 的建议,我安装了 RVM 并为 Ruby 1.9.2-p0 和 Gosu 设置 gemset。我设置了 TextMate 集成,但当尝试在 TextMate 中执行脚本时,我仍然收到永无休止的进度微调器。 TextMate 的 Ruby 包中的 run
命令显示如下:
#!/bin/sh
export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
/usr/bin/env ruby -KU -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb"
也许这里需要更改一些内容?
更新 2
在 TextMate 的“Shell 变量”首选项面板中,TM_RUBY
设置为 /Users/michael/.rvm/bin/rvm-auto-ruby
和 PATH
设置为 /Users/michael/.rvm/gems/ruby-1.9.2-p0@gosu/bin:/Users/michael/.rvm/gems/ruby-1.9.2-p0 @global/bin:/Users/michael/.rvm/rubies/ruby-1.9.2-p0/bin:/Users/michael/.rvm/bin:/usr/local/bin:/usr/local/sbin:/ usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
。
I'm learning basic game programming using Ruby and Gosu. I've installed Gosu from RubyGems, and it is currently sitting in /usr/local/lib/ruby/gems/1.9.1/gems/
.
The full path is /usr/local/lib/ruby/gems/1.9.1/gems/gosu-0.7.24-universal-darwin/
.
When I'm working on my game script, I can execute the file just fine using the terminal command ruby game.rb
. However, when I'm editing the script in TextMate and try to execute the script using command-R, the standard execution window comes up, but does nothing, save for a spinning progress indicator.
I've changed the owner of gosu-9.7.24-universal-darwin/
to myself and even tried changing the owner of the whole ruby/
directory (/usr/local/lib/ruby/
), but to no avail.
I'm using the standard Ruby bundle in TextMate.
Here is the script I'm trying to run, but the same event occurs on any of the example scripts:
require "rubygems"
require "gosu"
class GameWindow < Gosu::Window
def initialize
super(640,360, false)
self.caption = "Gosu Tutorial Game"
end
def update
end
def draw
end
def button_down(id)
if id == Gosu::KbEscape
close
end
end
end
window = GameWindow.new
window.show
Update
At Greg's suggestion, I installed RVM and set up a gemset for Ruby 1.9.2-p0 and Gosu. I set up TextMate integration but I am still getting the never-ending progress spinner when trying to execute my script in TextMate. The run
command in the Ruby bundle of TextMate shows to be thus:
#!/bin/sh
export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
/usr/bin/env ruby -KU -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb"
Perhaps something needs to change here?
Update 2
In my "Shell Variables" preference panel in TextMate, TM_RUBY
is set to /Users/michael/.rvm/bin/rvm-auto-ruby
and PATH
is set to /Users/michael/.rvm/gems/ruby-1.9.2-p0@gosu/bin:/Users/michael/.rvm/gems/ruby-1.9.2-p0@global/bin:/Users/michael/.rvm/rubies/ruby-1.9.2-p0/bin:/Users/michael/.rvm/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TextMate 不会继承与命令行应用程序相同的路径,因此您必须告诉它要查找的位置。
http://manual.macromates.com/en/shell_commands
为了长期保持理智,您可能需要要安装 RVM,请使用它来安装您的 Rubies,然后执行此处的步骤:https://rvm.io/integration /textmate/
TextMate doesn't inherit the same path as command-line apps, so you'll have to tell it where to look.
http://manual.macromates.com/en/shell_commands
For long term sanity, you might want to install RVM, use it to install your Rubies, then do the steps here: https://rvm.io/integration/textmate/
我遇到了类似的问题。所以我在脚本中添加了一个:
,发现它被设置到了错误的目录。所以我进去并设置了一个符号链接到 Gem.path 指向的位置,并将其设置为我的宝石实际所在的位置。现在我可以再次按下 command + r,一切都会像以前一样工作。
I've run into a similar issue. So I added a:
to my script and found out it was set to the wrong directory. So I went in there and set a symlink to where Gem.path pointed and set that to where my gems actually are. Now I can hit command + r again and everything works as it used to.