MineMcMine

JFuncs

Mar 30th, 2022 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. --[[
  2.     pastebin run kqBFGcfV
  3.     pastebin get kqBFGcfV miscFuncs.lua
  4. ]]--
  5.  
  6. function saveVar(name, value)
  7.     local file = fs.open("variables/" .. name, "w")
  8.     file.write(textutils.serialize(value))
  9.     file.close()
  10. end
  11.  
  12. function loadVar(name)
  13.     if(not fs.exists(name)) then
  14.         return nil
  15.     end
  16.  
  17.     local file = fs.open("variables/" .. name, "r")
  18.     local data = file.readAll()
  19.     file.close()
  20.     return textutils.unserialize(data)
  21. end
  22.  
  23. function hasVar(name)
  24.     return fs.exists(name)
  25. end
  26.  
  27. function dump(o)
  28.    if type(o) == 'table' then
  29.       local s = '{ '
  30.       for k,v in pairs(o) do
  31.          if type(k) ~= 'number' then k = '"'..k..'"' end
  32.          s = s .. '['..k..'] = ' .. dump(v) .. ','
  33.       end
  34.       return s .. '} '
  35.    else
  36.       return tostring(o)
  37.    end
  38. end
  39.  
  40. function printDump(o)
  41.    print(dump(o))
  42. end
  43.  
  44. function tableClone(orig)
  45.     local orig_type = type(orig)
  46.     local copy
  47.     if orig_type == 'table' then
  48.         copy = {}
  49.         for orig_key, orig_value in next, orig, nil do
  50.             copy[tableClone(orig_key)] = tableClone(orig_value)
  51.         end
  52.         setmetatable(copy, tableClone(getmetatable(orig)))
  53.     else -- number, string, boolean, etc
  54.         copy = orig
  55.     end
  56.     return copy
  57. end
  58.  
  59. function itemsEqual(item1, item2)
  60.     return (item1.name == item2.name and item1.damage == item2.damage and item1.nbtHash == item2.nbtHash)
  61. end
  62.  
Advertisement
Add Comment
Please, Sign In to add comment