lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Jul 28, 2016, at 4:56 AM, Thomas Jericke <tjericke@indel.ch> wrote:

On 28.07.2016 13:37, Dirk Laurie wrote:
2016-07-28 12:47 GMT+02:00 Thomas Jericke <tjericke@indel.ch>:

From the top of my head this is the most explicit statement. 

"Lua supports coroutines, also called collaborative multithreading. A coroutine in Lua represents an independent thread of execution. Unlike threads in multithread systems, however, a coroutine only suspends its execution by explicitly calling a yield function."

As you see in my example (that you cut from the quote), there is no yield in it. So the programmer rightfully can expect that the function is run uninterrupted.

Come now. As an imperative language, it is safe to assume that Lua will execute statements in the order listed. That is:

a; b
c

Will execute in the order a, b, c with each statement completed before the next begins. However, the order of execution within a statements is explicitly not guaranteed:

a = b() + c()

Could call b() first or c() first. Similarly, table constructor expressions may be evaluated in any order (as can an _expression_ list). There are good reasons for not specifying this order, as on some architectures it is easier to do things in one order rather than another.

Specifying that ‘#’ assignments are special just makes things messier:

a = {1, #, 2, 3}

I don’t think many people would intuitively expect # to be 3 in this case.

—Tim