[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 11:18:29 +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?
I'm not sure of the philosophical arguments but I provided a patch that implements just this only a couple of weeks ago.
http://lua-users.org/lists/lua-l/2016-05/msg00024.html
One limitation is that you cannot declare globals in the way you want to, globals are actually just table lookups in the `_ENV` table and you cannot really control table lookups. A common work-around for globals that I used prior to this patch was to declare all the globals I wanted as locals and the set `_ENV` to nil. This is a simple mechanism to get a runtime error on using undeclared globals (i.e. not copied to locals).
The patch has two effects, it declares which upvalues are allowed (or using `...` allows any) and also declares their order, which makes it much easier to dump and load pre-compiled functions.
Regards,
Duane.