[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: merging lua files
- From: Vaughan McAlley <vaughan@...>
- Date: Fri, 2 Jul 2010 20:59:35 +1000
On 2 July 2010 19:08, Duncan Cross <duncan.cross@gmail.com> wrote:
> On Fri, Jul 2, 2010 at 9:55 AM, Valerio Schiavoni
> <valerio.schiavoni@gmail.com> wrote:
>> hello Jerome
>>
>> On Fri, Jul 2, 2010 at 10:34 AM, Jerome Vuarand
>> <jerome.vuarand@gmail.com> wrote:
>>> Why do you need to merge the files ? What about conflicts between
>>> globals and locals (ie. the top file define a local foo, while the
>>> bottom file assumed it was a global) ?
>>
>> That's why I want to make a rewrite:
>>
>> --a.lua
>> foo={}
>>
>> --b.lua
>> local foo={}
>>
>> --merged.lua
>> a_foo={}
>> local b_foo={}
>>
>>
>> Maybe there are some caveats I don't see in this approach.
>>
>> I need to merge lua files because we need to support 'submission of
>> jobs' which are made by multiple files. The architecture is quite
>> complex, you can read more here:
>> http://www.splay-project.org/index.php?page=documentation
>>
>
> Wouldn't it be simpler to wrap a.lua and b.lua in generic "do" blocks?
>
> do
> -- a.lua
> local localorglobal = 100
> end
> do
> -- b.lua
> localorglobal = 1000
> end
>
> ...in fact, thinking about it, I don't think you'd technically need to
> do it for b.lua, but it doesn't hurt.
>
> -Duncan
>
I was also thinking along the lines of "do" blocks. You could also
clear the global table as you go:
local sharedGlobal1, sharedGlobal2
local old_G = _G
_G = setmetatable( {}, old_G)
function clear_G()
for k, v in pairs(_G) do
_G[k] = nil
end
end
do
foo = 100
end
clear_G()
do
-- b.lua
foo = "One hundred"
end
--Vaughan