Thanks Rendaw! I'll try that out next time we have mysterious happenings in our lua code. Maybe it will fill the same role for lua that valgrind plays for C/C+...
Cheers, Andrew On Sun, Jul 27, 2014 at 1:11 PM, Spooge <[email protected]> wrote: > > On 07/27/2014 04:19 PM, Andrew Wagner wrote: > >> >> Is it possible to disallow re-binding of variables in lua? >> > This prevents global reassignments, which I think handles most pollution > issues: > do > local globals = {} > setmetatable(_G, { > __index = globals, > __newindex = function(table, key, value) > if globals[key] ~= nil then error('Redefining ' .. > tostring(key)) end > globals[key] = value > end > }) > end > > As a test: > a = 4 > --a = 5 -- Error > print(a) > do > local x = 13 > x = x - 10 > local y = 27 > z = x + y > end > print(z) > > I used that at my previous job since we had a bunch of subprojects and > there was some pollution causing issues. > > > One thing that is clear is that in almost build specifications (including >> all of mine), people are frequently mutating lists of strings that get >> passed into compilers, and lists of dependencies. So if you remove the >> ability to do stuff like: >> >> FOO=-IA >> (specify rule 1 using A) >> FOO+=-IB >> (specify rule 2 using B) >> FOO+=-IC >> (specify rule 3 using A and C, and also has B as cruft because the >> programmer was lazy) >> >> You need to have a very lightweight alternative. Maybe something like: >> FOO=-IA >> specify rule 1 needing A >> ( >> FOO+=-IB >> (specify rule 2 using B) >> ) >> ( >> FOO+=-IC >> (Specify rule 3 using A and C, with no B cruft since the programmer >> wasn't allowed to be lazy) >> ) >> >> You can use explicit blocks and locals to do that: > FOO='-lA' > do > local FOO = FOO..' -lB' > end > do > local FOO = FOO..' -lC' > end > print(FOO) > > Cheers, > Rendaw > > > -- > -- > tup-users mailing list > email: [email protected] > unsubscribe: [email protected] > options: http://groups.google.com/group/tup-users?hl=en > --- You received this message because you are subscribed to the Google > Groups "tup-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- tup-users mailing list email: [email protected] unsubscribe: [email protected] options: http://groups.google.com/group/tup-users?hl=en --- You received this message because you are subscribed to the Google Groups "tup-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
