diff options
Diffstat (limited to 'library/lua/dfhack.lua')
| -rw-r--r-- | library/lua/dfhack.lua | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index d56d4df6..2cbd019a 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -39,6 +39,8 @@ if dfhack.is_core_context then SC_MAP_UNLOADED = 3 SC_VIEWSCREEN_CHANGED = 4 SC_CORE_INITIALIZED = 5 + SC_PAUSED = 7 + SC_UNPAUSED = 8 end -- Error handling @@ -100,11 +102,39 @@ function reload(module) dofile(path) end +-- Trivial classes + +function rawset_default(target,source) + for k,v in pairs(source) do + if rawget(target,k) == nil then + rawset(target,k,v) + end + end +end + +function defclass(class,parent) + class = class or {} + rawset_default(class, { __index = class }) + if parent then + setmetatable(class, parent) + else + rawset_default(class, { init_fields = rawset_default }) + end + return class +end + +function mkinstance(class,table) + table = table or {} + setmetatable(table, class) + return table +end + -- Misc functions function printall(table) - if type(table) == 'table' or df.isvalid(table) == 'ref' then - for k,v in pairs(table) do + local ok,f,t,k = pcall(pairs,table) + if ok then + for k,v in f,t,k do print(string.format("%-23s\t = %s",tostring(k),tostring(v))) end end @@ -133,14 +163,6 @@ function xyz2pos(x,y,z) end end -function rawset_default(target,source) - for k,v in pairs(source) do - if rawget(target,k) == nil then - rawset(target,k,v) - end - end -end - function safe_index(obj,idx,...) if obj == nil or idx == nil then return nil @@ -158,10 +180,6 @@ end -- String conversions -function dfhack.event:__tostring() - return "<event>" -end - function dfhack.persistent:__tostring() return "<persistent "..self.entry_id..":"..self.key.."=\"" ..self.value.."\":"..table.concat(self.ints,",")..">" |
