News for hackers. Stuff that matters.
Re:Learn Lua in 15 Minutes (2013) by AceJohnny2 on Tuesday June 30, 2020 @06:45PM (#23695678)
How does it compare to TCL?

I understand that the fact of the matter is that Lua dominates, but I'm curious if there are technical reasons or "right thing/right time" kind of luck, after TCL's star dimmed.

Re:Learn Lua in 15 Minutes (2013) by ufo on Tuesday June 30, 2020 @10:46PM (#23697213)
I'm not sure there is an easy answer for the question of why one language became more popular than the other but there some very interesting parallels that can be drawn between Lua and TCL. One thing that both have in common is that both languages were purposefully designed to be able to be embedded with other languages, such as C. But they do this in very different ways.

The problem of embedding one language inside another is how do you make code written in one language call functions and objects defined in the other language? For example, when an object is transferred from the scripting language to the host language, how does the garbage collector keep track of it? This isn't easy to do and in some languages it is quite cumbersome. For instance, in Python the C programmer has to manually increment and decrement the reference counts for the python objects that they interact with.

TCL solves this problem by making everything a string, taking the "everything is a string" mantra farther than any other programming language. Strings are easy to pass from one language to the other.

Lua went the opposite direction. Lua exposes a rich API that lets other languages interact with Lua. The API lets other languages create Lua objects and call Lua functions, as well as send C objects and functions to Lua. Lua is entirely designed around this API and even the core standard library is built using it, ensuring that every Lua feature is accessible to C code as well. One interesting example of this is exception handling. In most languages this is done using try-catch blocks. But that feature isn't easy to use when embedding one language inside another. How would you write try-catch blocks in C? Because of this, Lua has a different way to do exception handling. Instead of try-catch blocks, there is a "pcall" function that invokes a function and returns whether there was an exception or not. Function calls and if-then-else statements are things that are also available to other languages via the Lua API...

    local ok, err = pcall(function()
        something_that_may_throw_an_exception()
    end)
    if not ok then
        -- handle exception
    end
Re:Learn Lua in 15 Minutes (2013) by brians on Tuesday June 30, 2020 @08:34PM (#23696439)
That’s a really good comparison!

Lua has real types in a dynamic language; in Tcl everything is a string.

They can both pass functions around, but Tcl’s work by “eval” all the time—so security is quite tricky. Lua has real higher order functions.

Lua has lexical scope. In fact, by semantics it’s almost a Scheme dialect (say, R4RS) with extraordinary syntax.

Re:Learn Lua in 15 Minutes (2013) by Symmetry on Wednesday July 01, 2020 @09:32AM (#23701101)
Scheme in ALGOL's clothing, with the lists swapped out for hash tables is how I sometimes describe it.
Re:Learn Lua in 15 Minutes (2013) by corysama on Tuesday June 30, 2020 @07:33PM (#23696054)
Don't know much about TCL. But, if you are familiar with JavaScript, Lua ended up being semantically a much cleaner, simpler JS without all the WOT?? and committees to please.

It is small, fast, simple, powerful and easy to embed.

It's also very easy to contain in that the standard library is small and most of that can be removed easily. Isolating Lua's allocation arena and controlling Lua's GC is pretty easy.

Re:Learn Lua in 15 Minutes (2013) by hajile on Tuesday June 30, 2020 @10:18PM (#23697022)
All the little operators that make things nice like += are missing. Their object implementation is meta-tables, so every single codebase does stuff in fundamentally different paradigms. Operator overloading in such a dynamic language makes things extremely hard to understand. While `"0" == 0` is false, the language will still sloppily convert between floats and ints and will also convert strings to numbers in other places. Worst of all, array indexes are base 1.
Re:Learn Lua in 15 Minutes (2013) by hombre_fatal on Wednesday July 01, 2020 @03:36AM (#23698853)
Lua manages to surprise even Javascript developers with how bad its standard library is.
Re:Learn Lua in 15 Minutes (2013) by catalogia on Tuesday June 30, 2020 @08:16PM (#23696349)
mpv supports both Lua and Javascript scripting, with more or less the same API for both. The wiki lists 10 scripts from the community written in Javascript vs a few hundred written in Lua. There are probably network effects in play; people choose Lua because that allows them to mine snippets of code from a larger collection of userscripts. Even so though, I think it's a testament to Lua.

https://github.com/mpv-player/mpv/wiki/User-Scripts

Re:Learn Lua in 15 Minutes (2013) by panzagl on Tuesday June 30, 2020 @08:56PM (#23696598)
JavaScript moves so fast- it's gone from WAT to WOT
Re:Learn Lua in 15 Minutes (2013) by tyingq on Wednesday July 01, 2020 @07:54AM (#23700427)
Squirrel-lang is worth a look as well. http://www.squirrel-lang.org
Re:Learn Lua in 15 Minutes (2013) by CyberDildonics on Wednesday July 01, 2020 @09:19AM (#23700981)
There is barely a comparison to be made. Lua is faster, LuaJIT is much faster, lua is much easier to embed and lua is much more elegant and way less awkward to program in. TCL ends up being funky and lua ends up working.

When there was no competition in the space of already made scripting languages that were easy to embed (except for possibly perl) TCL had a place, but it is a relic of the past now and for good reason.