[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why not Just PHP-stupid include?
- From: Florian Weimer <fw@...>
- Date: Tue, 18 Oct 2011 14:29:03 +0200
* Patrick Mc:
> I don't want to have to pack x into a table and return it, on the
> other end I don't want to have to define a new local variable to
> receive the payload from require. PHP is a poorly constructed language
> but include just switches execution from one file to the other and
> then goes back to the first, it's dead simple to pick this up.
Both things are not totally unrelated, unfortunately. Lua has proper
lexical scoping, and each file ends up in its own chunk. So when you
write
local x = 1
in one file, it only affects that scope. It works as expected if you
drop the "local".
I think it will be possible in Lua 5.2 to use the "debug" library
("upvaluejoin" in particular) to obtain the effect you desire.
I'm not sure if that's a good idea, though.