ruby: add onstatechange_register_once

develop
jj 2012-09-26 15:08:54 +02:00
parent f628c3732a
commit d975ce5135
1 changed files with 8 additions and 0 deletions

@ -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 ||= []