Advertisement
posicat

/config

Sep 15th, 2024 (edited)
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. --File: /config
  2. dofile("/cattech/file.lua")
  3.  
  4. -- Function to display the value of a key in the hash
  5. local function getValue(hash,key)
  6.     if hash[key] then
  7.         print(key .. ": " .. tostring(hash[key]))
  8.     else
  9.         print("Key '" .. key .. "' not found in the hash.")
  10.     end
  11. end
  12.  
  13. -- Function to set a key-value pair in the hash
  14. local function setValue(hash,key, value)
  15.     hash[key] = value
  16.     print("Set " .. key .. " to " .. tostring(value))
  17. end
  18.  
  19. -- Main program
  20. local args = {...} -- Get command line arguments
  21.  
  22. local config = loadHash(defaultConfig)
  23.  
  24. if #args == 1 then
  25.     -- If 1 parameter, list the value of the hash using that key
  26.     getValue(config,args[1])
  27. elseif #args == 2 then
  28.     -- If 2 parameters, set the key-value pair in the hash
  29.     local par2 = args[2]
  30.     if par2 == "nil" then
  31.         par2 = nil
  32.     end
  33.     setValue(config,args[1], par2)
  34. else
  35.     displayHash(config)
  36.     print("Usage: <program> <key> [value]")
  37. end
  38.  
  39. saveHash(defaultConfig,config)
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement