lua-users home
lua-l archive

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


On Sep 15, 2014 3:07 AM, "Tom N Harris" <telliamed@whoopdedo.org> wrote:

> Also relevant when __newindex is defined on the metatable and has side-
> effects.
>
> But I think you'd have to be some kind of sadist to put side-effects in a
> metatable function. Nothing obfuscates a program more than when what looks
> like a simple `=' sign means more than just assign a value to the lvalue.

It is difficult to read tone of voice, and I am afraid I am taking a joke seriously, but:

It is a common pattern to map Lua tables to C-side objects in a way that Lua

  window.title = "Shine"

is mapped to a C function call:

  jtk_window_set_title(w, "Shine");

which will manifest as some cascade of window system interactions eventually displaying the title.

The least-side-effect strategy is to clone the string into a "pending updates" list and mark the window for redraw by the event loop. I don't think I've ever seen that, but even the mark is a side effect.

In some bindings, interaction with a key requires a lazily-allocated underlying C object to be materialized. This may have visible effects.

I think "t[k]=v should have no side effects" means all assignments may be reordered in any way such that references t[k] remain causally ordered. I think that's perhaps too high a goal; it rules out properties, and properties are what many casual programmers expect.

Jay