2 ms·
I forgot to emphasize that I'm particular about syntax. I amended my comment accordingly. I also don't like the global-by-default bit, but maybe my ideal langua
by weberc2 9y ago
I forgot to emphasize that I'm particular about syntax. I amended my comment accordingly. I also don't like the global-by-default bit, but maybe my ideal language could be a syntax layer atop Lua?
- rweichler 9y agoMetatables are your friend. -- LuaJIT local oldG = _G local newG = setmetatable({}, { __index = oldG, }) setmetatable(oldG, { __index = function(t, k) return rawget(newG, k) end, __newindex = function() error('attempt to assign global variable') end, }) _G = newG If you want to assign a global variable, `x = 5` will error but `_G.x = 5` won't.
- vanderZwan 9y agoIf you ignore the class support of moonscript, you can pretty much use it to do what you want. It doesn't have the "global by default" silliness, to start with.