lua-users home
lua-l archive

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

On Fri, Apr 13, 2007 at 04:32:43PM +0200, Olivier Delannoy wrote:
> On 4/13/07, Olivier Galibert <> wrote:
> >On Fri, Apr 13, 2007 at 03:27:17PM +0200, Olivier Delannoy wrote:
> >> Lua should not evolve in a way that makes the language more complex
> >> and not clear for the sake of not writing a few more extra characters.
> >> Lua is small and should stay small. 1 more vote against += -= *= /= --
> >> ++ and all other operator added to the language for programmer
> >> lazyness. If one want all this operation its another language and it
> >> can go with one providing this kind of facility.
> >
> >Oh please.  Read the thread you're replying to, if += and ++ were
> >*only* syntaxic sugar it wouldn't be a problem to add them.  It's
> >because they imply way more than that that there are issues.
> >
> In what i++ is different from i = i + 1 (I assume post increment here.)

The obvious: keyword[i++] = "continue"

The less obvious: i = i + 1 <=> i = i:add(1)
                  i++       <=> i:increment()

Add produces a new object and assigns it to 'i', increment changes the
value pointed to by 'i' it in-place.  If 'i' was a parameter of a
function and the content is a table or a pointer-as-userdata, the
caller will see the change with ++, not with +.

> Could you details the in-place modification in the context of the lua
> stack and state please ?

See above.

> Atomicity as no meaning in lua. Lua is not multi threaded and there is
> only one execution thread per state active at a time. so a whool chunk
> can fairly well be considered atomic.

lua itself is cooperatively multi-threaded, and in any case lua makes
no assumption about the application it is immersed into.

> Why : is more complex than it appears ?
> a.truc(a, something) is strictly equivalent to a:truc(something)

Err, no it isn't.  Add a _index function in the table or userdata a
points to.  Have the function change the value of the variable 'a' on
the 'truc' lookup.  With '.' the final function will be called with
the new value of 'a', with ':' with the old one.

That is, incidentally, an example of atomicity assumption.  ':' is