[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Namespace advice needed
- From: Julien Duminil <julien.duminil@...>
- Date: Thu, 24 Feb 2011 14:31:29 +0100
Maybe you could do a thing like:
acme = {}
-- Replace global table with acme
local old_G = _G
setmetatable(acme, { __index = old_G })
_G = acme
-- Require sub namespaces
require "my_lib_with_a_lot_of_namespaces"
-- Restore global table
_G = old_G
setmetatable(acme, nil)
or a C equivalent, so you catch every sub namespaces ...
Regards, Julien.
PS: i've not tested this code, sorry if it's wrong :)
---------------------------------------------------------------------------------------------
De : lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] De la part de Jeff Smith
Envoyé : mercredi 23 février 2011 22:53
À : lua-l@lists.lua.org
Objet : RE: Namespace advice needed
Hi Luiz
Thanks for the speedy reply
> This is simpler:
> acme={graphics=graphics}
> graphics=nil
Ooops, yes that is the better way of doing it. I did type that originally but I changed it as I wrongly thought the following graphics = nil line would cause the acme table to get its graphics table entry also deleted. Newbie alert !
Anyway, the main gist of my question still applies, which of the 3 options listed is the better way of doing this?
Regards Geoff
PS. looks like I double posted somehow, sorry not sure what caused that.
> Date: Wed, 23 Feb 2011 18:34:18 -0300
> From: lhf@tecgraf.puc-rio.br
> To: lua-l@lists.lua.org
> Subject: Re: Namespace advice needed
>
> > -- for each table I need to move,
> > acme={}
> > acme.graphics={}
> > for k,v in pairs(graphics) do
> > acme.graphics[k] = v
> > end
> > graphics = nil
>
> This is simpler:
> acme={graphics=graphics}
> graphics=nil
>