News for hackers. Stuff that matters.
Re:MoonScript, a programmer friendly language that compiles ... by RyanSquared on Monday May 29, 2017 @05:52PM (#14441675)
This is basically Lua, excluding type annotations. Lua's form of OOP is very strange in that methods aren't bound to a parent context, but instead take the object as a value. For example, `object:method()` is the same as `object.method(object)`, and `function object:method()` is the same as `function object.method(self)` - the only difference being calling the function via `object:method()` is a bit more optimized. There is also a framework with networking, signals, and other cool features called `cqueues` which works based off of coroutines.s You might want to check that out too :)
Re:MoonScript, a programmer friendly language that compiles ... by Cyph0n on Monday May 29, 2017 @05:57PM (#14441698)
And the size of the Lua runtime is nothing short of beautiful. I have yet to find a use for Lua though, so I'm still waiting for an opportunity to work on something with it.
Re:MoonScript, a programmer friendly language that compiles ... by RyanSquared on Monday May 29, 2017 @06:00PM (#14441720)
I find it's used a lot in places you wouldn't expect. I found it used in a car radio, the modem used in my house, and a few other places. It's lightweight if you want to use it on embedded systems (for example, NodeMCU) if you're into that kind of thing.
Re:MoonScript, a programmer friendly language that compiles ... by wcummings on Monday May 29, 2017 @06:26PM (#14441829)
Iirc its used on some digital cameras as well.
Re:MoonScript, a programmer friendly language that compiles ... by spc476 on Monday May 29, 2017 @11:24PM (#14442850)
I'm using it at work to parse SIP messages (with LPeg) for one of our customers (one of the cellphone carriers). Between LPeg for parsing, and coroutines in Lua, the code is pretty easy to read and follow.
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.