lua-users home
lua-l archive

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


> Is this what you're trying to do?
> local meta
> meta = {
>	__index = function(t, k)
>		print("__index", t, k)
>		if(not rawget(t, k)) then
>			rawset(t, k, setmetatable({}, meta))
>		end
>		return t[k]
>	end,	
>	__newindex = function(t, k, v)
>		print("__newindex", t, k, v)
>		rawset(t, k, v)
>	end
> }
> -- config.network.server.url
> local config = setmetatable({}, meta)
> config.network.server.url = "http://www.lua.org";

That's basically where I stopped searching with standard Lua: your example has two 'side effects'. If you access (read) a field that does not exist (ex : return config.toto.tata):
	it returns a table instead of nil
	it fills in the config table with empty tables