News for hackers. Stuff that matters.
Re:MoonScript, a programmer friendly language that compiles ... by weberc2 on Monday May 29, 2017 @07:44PM (#14442122)
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?
Re:MoonScript, a programmer friendly language that compiles ... by rweichler on Monday May 29, 2017 @08:27PM (#14442291)
Metatables 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.
Re:MoonScript, a programmer friendly language that compiles ... by vanderZwan on Tuesday May 30, 2017 @02:54AM (#14443355)
If 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.