ruby: link libruby, fix stuff, it works

develop
jj 2012-03-21 19:30:31 +01:00
parent b2846492f4
commit f46e1ee518
3 changed files with 45 additions and 40 deletions

@ -2,6 +2,8 @@ find_package(Ruby)
if(RUBY_FOUND) if(RUBY_FOUND)
include_directories("${dfhack_SOURCE_DIR}/depends/tthread" ${RUBY_INCLUDE_PATH}) include_directories("${dfhack_SOURCE_DIR}/depends/tthread" ${RUBY_INCLUDE_PATH})
DFHACK_PLUGIN(ruby ruby.cpp LINK_LIBRARIES dfhack-tinythread) DFHACK_PLUGIN(ruby ruby.cpp LINK_LIBRARIES dfhack-tinythread)
target_link_libraries(ruby ${RUBY_LIBRARY})
install(FILES ruby.rb DESTINATION ${DFHACK_LIBRARY_DESTINATION})
else(RUBY_FOUND) else(RUBY_FOUND)
MESSAGE(STATUS "Required library (ruby) not found - ruby plugin can't be built.") MESSAGE(STATUS "Required library (ruby) not found - ruby plugin can't be built.")
endif(RUBY_FOUND) endif(RUBY_FOUND)

@ -44,6 +44,7 @@ DFHACK_PLUGIN("ruby")
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
out.print("plugin_init\n");
m_irun = new tthread::mutex(); m_irun = new tthread::mutex();
m_mutex = new tthread::mutex(); m_mutex = new tthread::mutex();
r_type = RB_INIT; r_type = RB_INIT;
@ -72,6 +73,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
"Ruby interpreter dev. Eval() a ruby string.", "Ruby interpreter dev. Eval() a ruby string.",
df_rubyeval)); df_rubyeval));
out.print("plugin_init done\n");
return CR_OK; return CR_OK;
} }
@ -521,6 +523,7 @@ static void ruby_bind_world(void) {
rb_c_world_T_units = rb_define_class_under(rb_c_world, "T_units", rb_c_WrapData); rb_c_world_T_units = rb_define_class_under(rb_c_world, "T_units", rb_c_WrapData);
rb_define_method(rb_c_world, "units", RUBY_METHOD_FUNC(rb_m_world_units), 0); rb_define_method(rb_c_world, "units", RUBY_METHOD_FUNC(rb_m_world_units), 0);
rb_define_method(rb_c_world_T_units, "all", RUBY_METHOD_FUNC(rb_m_world_T_units_all), 0);
} }
static VALUE rb_global_world(VALUE self) { static VALUE rb_global_world(VALUE self) {
@ -603,7 +606,7 @@ static void ruby_bind_dfhack(void) {
// load the default ruby-level definitions // load the default ruby-level definitions
int state=0; int state=0;
rb_load_protect(rb_str_new2("./hack/plugins/ruby.rb"), Qfalse, &state); rb_load_protect(rb_str_new2("./hack/ruby.rb"), Qfalse, &state);
if (state) if (state)
dump_rb_error(); dump_rb_error();
} }

@ -1,43 +1,43 @@
module DFHack module DFHack
def suspend class << self
if block_given? def suspend
begin if block_given?
do_suspend begin
yield do_suspend
ensure yield
resume ensure
end resume
else end
do_suspend else
end do_suspend
end end
end
def puts(*a)
a.flatten.each { |l| def puts(*a)
print_str(l.to_s.chomp + "\n") a.flatten.each { |l|
} print_str(l.to_s.chomp + "\n")
end }
end
def puts_err(*a)
a.flatten.each { |l| def puts_err(*a)
print_err(l.to_s.chomp + "\n") a.flatten.each { |l|
} print_err(l.to_s.chomp + "\n")
end }
end
def test
puts "starting" def test
puts "starting"
suspend {
c = cursor suspend {
puts "cursor pos: #{c.x} #{c.y} #{c.z}" c = cursor
puts "cursor pos: #{c.x} #{c.y} #{c.z}"
puts "unit[0] id: #{world.units.all[0].id}"
} puts "unit[0] id: #{world.units.all[0].id}"
}
puts "done"
end puts "done"
end end
end
end end
# load user-specified startup file # load user-specified startup file