lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Sorry about the non-sense code I posted earlier, clearly I don't understand nested tables and/or how to define them local to their parent table and should have tested it before posting.

This code works and I don't actually want mainLoop.library1.z to return true.

local mainLoop = {}
mainLoop.library1 = {}
mainLoop.library2 = {}
mainLoop.library1.x = 1
mainLoop.library2.y = 2
mainLoop.library1.z = mainLoop.library2.y
print(mainLoop.library1.z)
-->2    --wish it returned nil

Sean Conner's code used Meta tables:
""
local dns    = org.conman.dns
local debug  = setmetatable(org.conman.debug  , { __index = _G.debug  })
local string = setmetatable(org.conman.string , { __index = _G.string })
"""

Is there a way to have nested tables that do not have access to each other? Is this why Sean needed to use meta tables?

Sean's strategy surely would work just fine but I tend to be shy of meta tables due to lack of experience.

Thanks for reading-Patrick



On 12/27/2010 06:09 PM, Patrick Mc(avery wrote:
<blush>Whoa, I think I totally botched that example</blush>

I'll be back....



On 12/27/2010 05:52 PM, Patrick Mc(avery wrote:
Hi Sean

Thanks for your response and thanks to Tomás, David and Steve too.

If I understand this right could someone do this:
mainloop = {}
local mainLoop.library1 = {}
local mainLoop.library2 = {}
cont....

Then would the "main loop"(for lack of better term) have access to the
library code but the library code would not have access to other
libraries?

To split it up into a variety of files could one just use dofile() to
connect it all together?

Could such a layout scale up into the 10's of thousands of lines of code?

Thanks again-Patrick