summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/ruby/ruby.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb
index aeae101d..81b73b7c 100644
--- a/plugins/ruby/ruby.rb
+++ b/plugins/ruby/ruby.rb
@@ -119,6 +119,14 @@ module DFHack
@onstatechange_list.delete b
end
+ # same as onstatechange_register, but auto-unregisters if the block returns true
+ def onstatechange_register_once
+ handle = onstatechange_register { |st|
+ onstatechange_unregister(handle) if yield(st)
+ }
+ end
+
+
# this method is called by dfhack every 'onstatechange'
def onstatechange(newstate)
@onstatechange_list ||= []