[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: explicit mode
- From: Duane Leslie <parakleta@...>
- Date: Wed, 11 May 2016 12:12:17 +1000
> Still: what speaks against implementing a new Lua compilation mode where everything must be explicitly declared to be either local or global, and anything not so declared would result in a compilation error?
On further consideration, my proposal for declared upvalues is much more powerful than you need, but subsumes the functionality you are after. For the simplest possible solution you could just use a label based pragma to disable the implied `_ENV` upvalue and this would be the simplest solution which would actually also allow your code to run on an unmodified Lua interpreter. Then any function which opens with for example `::__NO_ENV::` before any other statement would have no globals available at compile time. You can extract this statement by modifying the `labelstat()` function in `lparser.c` to look for pragma labels when `fs->pc == 0`.
You need to be careful when modifying `singlevar()` to handle both the case that the variable isn't found (in functions where you've disabled `_ENV`), and the case that the `_ENV` upvalue isn't found (in the closures within the functions with disabled `_ENV`).
Regards,
Duane.