This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Creator's profile picture

Virtual File System

Started by Creator, 06 May 2015 - 08:24 AM
Creator #1
Posted 06 May 2015 - 10:24 AM
Hi guys,

I am working on a vfs, and am having some troubles with tables.

Spoiler

--[[
VFS by Creator
]]--
--Variables
local filesystem = {}

--Functions
function makeTable(t,path)
path = fs.combine("",path)
print(path)
local first = path:match("[^/]+")
if first then
  if t[first] then
   return makeTable(t[first],path:sub(#first+2,-1))
  else
   t[first] = {}
   return makeTable(t[first],path:sub(#first+2,-1))
  end
else
  print(t)
  return t
end
end
tab = nil
hi = nil
tab = makeTable(_G,"hi////there/how/are/you")
hi.there.how.are.you = {[1] = true,[2] = "well"}
tab.youhou = "sdg"
print(hi.there.how.are.you)
print(tab)
print(textutils.serialize(hi.there.how.are.you))
print(textutils.serialize(tab))

What I am excpecting is that the tables tab and hi.there.how.are.you should be equal. However this is not the case. Why does this happen?
Bomb Bloke #2
Posted 06 May 2015 - 11:07 AM
tab = makeTable(_G,"hi////there/how/are/you")  -- Creates "hi.there.how.are.you", and sets "tab" to point to that same table.
hi.there.how.are.you = {[1] = true,[2] = "well"}     -- Sets "hi.there.how.are.you" to point at a new, different table. Does not also alter tab.
Creator #3
Posted 06 May 2015 - 12:23 PM
Oh, thank you. Basic error. :)/>