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)
include_directories("${dfhack_SOURCE_DIR}/depends/tthread" ${RUBY_INCLUDE_PATH})
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)
MESSAGE(STATUS "Required library (ruby) not found - ruby plugin can't be built.")
endif(RUBY_FOUND)

@ -44,6 +44,7 @@ DFHACK_PLUGIN("ruby")
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
out.print("plugin_init\n");
m_irun = new tthread::mutex();
m_mutex = new tthread::mutex();
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.",
df_rubyeval));
out.print("plugin_init done\n");
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_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) {
@ -603,7 +606,7 @@ static void ruby_bind_dfhack(void) {
// load the default ruby-level definitions
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)
dump_rb_error();
}

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