summaryrefslogtreecommitdiff
path: root/library/lua
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-09-29 17:21:49 +0400
committerAlexander Gavrilov2012-09-29 17:21:49 +0400
commit62cde96724622a08f9dd6d4bf83f1763a02fd9df (patch)
tree99862f565d7d8e30ab054a3ff01a35aab5044669 /library/lua
parent48da06ec371421a48f801f6da1add6e437ccfa06 (diff)
downloaddfhack-62cde96724622a08f9dd6d4bf83f1763a02fd9df.tar.gz
dfhack-62cde96724622a08f9dd6d4bf83f1763a02fd9df.tar.bz2
dfhack-62cde96724622a08f9dd6d4bf83f1763a02fd9df.tar.xz
Add a script to reclassify 'individual choice' weapons based on unit skill.
Diffstat (limited to 'library/lua')
-rw-r--r--library/lua/utils.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/library/lua/utils.lua b/library/lua/utils.lua
index 9fa473ed..b46363cd 100644
--- a/library/lua/utils.lua
+++ b/library/lua/utils.lua
@@ -361,6 +361,27 @@ function insert_or_update(vector,item,field,cmp)
return added,cur,pos
end
+-- Binary search and erase
+function erase_sorted_key(vector,key,field,cmp)
+ local cur,found,pos = binsearch(vector,key,field,cmp)
+ if found then
+ if df.isvalid(vector) then
+ vector:erase(pos)
+ else
+ table.remove(vector, pos)
+ end
+ end
+ return found,cur,pos
+end
+
+function erase_sorted(vector,item,field,cmp)
+ local key = item
+ if field and item then
+ key = item[field]
+ end
+ return erase_sorted_key(vector,key,field,cmp)
+end
+
-- Calls a method with a string temporary
function call_with_string(obj,methodname,...)
return dfhack.with_temp_object(