iteration

This commit is contained in:
Layla 2023-10-08 01:56:24 -04:00
parent d0ea038cdb
commit f63ab77fc1

20
lns.lua
View File

@ -18,6 +18,22 @@ settings.define("lns_client.lns_server", {
allow_dynamic_lns_hosts = settings.get("lns_client.allow_dynamic_lns_hosts")
lns_server_id = settings.get("lns_client.lns_server")
function load_cache()
if fs.exists("lns_cache.db") then
db = fs.open("lns_cache.db", "r")
db_contents = db.readAll()
db.close()
cache = textutils.unserialize(db_contents)
end
end
function save_cache()
db = fs.open("lns_cache.db", "w")
db.write(textutils.serialize(cache))
db.close()
end
function lns_lookup(remote_hostname)
local data = {
["action"] = "lookup",
@ -46,6 +62,9 @@ function lns_lookup(remote_hostname)
end
end
load_cache()
local action = args[1]
if action == nil then
io.write("Usage: lns <action>\n")
@ -68,6 +87,7 @@ if action == "lookup" then
if result ~= nil then
io.write(result)
cache[hostname] = result
save_cache()
end
elseif action == "clear" then