diff options
Diffstat (limited to 'library/lua/utils.lua')
| -rw-r--r-- | library/lua/utils.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/library/lua/utils.lua b/library/lua/utils.lua index 38a1e6c4..9fa473ed 100644 --- a/library/lua/utils.lua +++ b/library/lua/utils.lua @@ -361,6 +361,39 @@ function insert_or_update(vector,item,field,cmp) return added,cur,pos end +-- Calls a method with a string temporary +function call_with_string(obj,methodname,...) + return dfhack.with_temp_object( + df.new "string", + function(str,obj,methodname,...) + obj[methodname](obj,str,...) + return str.value + end, + obj,methodname,... + ) +end + +function getBuildingName(building) + return call_with_string(building, 'getName') +end + +function getBuildingCenter(building) + return xyz2pos(building.centerx, building.centery, building.z) +end + +function split_string(self, delimiter) + local result = { } + local from = 1 + local delim_from, delim_to = string.find( self, delimiter, from ) + while delim_from do + table.insert( result, string.sub( self, from , delim_from-1 ) ) + from = delim_to + 1 + delim_from, delim_to = string.find( self, delimiter, from ) + end + table.insert( result, string.sub( self, from ) ) + return result +end + -- Ask a yes-no question function prompt_yes_no(msg,default) local prompt = msg |
