Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
SpaceBeeGaming

Serialization problems

Question

So, I have been working on an API which allows me to assign additional addresses to computers. And No I have a moment of confusion:

function internal.dns.loadHosts()
  local HOST_FILE_LOC = os.getenv("HOST_FILE_LOC")
  print(HOST_FILE_LOC) --Prints /usr/misc/hosts.txt
  assert(HOST_FILE_LOC, "Missing environment variable: HOST_FILE_LOC pointing to a file used for storing dns mamppings ")
  if (filesystem.exists(HOST_FILE_LOC)) then
    local hostFile = io.open(HOST_FILE_LOC)
    print(serialization.unserialize(hostFile:read("*all"))) --prints a table
    local hosts
    hosts = serialization.unserialize(hostFile:read("*all"))
    print(hosts) -- prints nil
    hostFile:close()
    return hosts --Return a table of hosts, if successful
  else
    return nil --Return nil if hostfile doesnt exist
  end
end

Why is it that these two seemingly same calls return different values. one is table other is nil?

Link to post
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.