lua-users home
lua-l archive

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


>> Why not, say, wrap access to "shared" tables into some API calls (if
>> needed, it may be made transparent by implementing a clever metatable
>> over a global environment)? Such API may call yield as needed then (if
>> you put into a metatable, you'll need to employ one of
>> cross-metamethod yielding libraries).

> It's probably doable, but I think it leads to awkward code:

>    1. The script programmers would then have to keep track of which
> tables are foreign vs. local.

This is not a big price to pay for simplicity of implementation.
You'll have to do this anyway sooner or later to control amount of
data transferred between instances.

>    2. Code becomes bulky (and maybe slow):

>       player.inventory["mushrooms"]=player.inventory["mushrooms"]+1;

>          instead of

> MakeRes(MakeRes(player).inventory)["mushrooms"]=MakeRes(MakeRes(player).inventory)["mushrooms"]+1

Er... I do not see where from nested MakeRes calls came from.

This should be possible in most of sane implementations:

local player = SHARED.player
player.inventory["mushrooms"] = player.inventory["mushrooms"] + 1

>    3. I investigated the metamethod idea - there's no way to define a
> metamethod for changing an existing key, as in the above example. (Right?)

As it was suggested, use a proxy table (put a metatable over an empty
table, but store all data elsewhere).

>    4. Tables can point to other tables to form complex data structures.
> Without a global ID for each table, knowing which tables to send to
> connected players becomes a nightmare.

I'm not sure why do you need global IDs. If you use a single root
(SHARED object in the example above), you should be able to
synchronize data trees without having them explicitly.

> Requiring programmers to always
> initialize this for each table is error prone, and interferes with
> garbage collection because now an "empty" table isn't really empty.

I'm not sure how can this interfere with GC. If table is not
referenced anywhere, it would be collected regardless of its contents.

* * *

The decision is, of course, yours, but, I believe, that the risks
you're taking with changing Lua itself are *much* higher than benefit
you'll get.

Alexander.