Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --File: /config
- dofile("/cattech/file.lua")
- -- Function to display the value of a key in the hash
- local function getValue(hash,key)
- if hash[key] then
- print(key .. ": " .. tostring(hash[key]))
- else
- print("Key '" .. key .. "' not found in the hash.")
- end
- end
- -- Function to set a key-value pair in the hash
- local function setValue(hash,key, value)
- hash[key] = value
- print("Set " .. key .. " to " .. tostring(value))
- end
- -- Main program
- local args = {...} -- Get command line arguments
- local config = loadHash(defaultConfig)
- if #args == 1 then
- -- If 1 parameter, list the value of the hash using that key
- getValue(config,args[1])
- elseif #args == 2 then
- -- If 2 parameters, set the key-value pair in the hash
- local par2 = args[2]
- if par2 == "nil" then
- par2 = nil
- end
- setValue(config,args[1], par2)
- else
- displayHash(config)
- print("Usage: <program> <key> [value]")
- end
- saveHash(defaultConfig,config)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement