lua-users home
lua-l archive

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


On Wed, Apr 16, 2014 at 9:14 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
> On the other hand the polymorphism is totally superfluous so far, because
> AFAIK no-one has implemented an additional string type for Lua yet (the
> UTF-8 strings use normal Lua strings as backend, so the shared metatable
> prevents you from providing specialized methods for them).

It's sometimes called the "virtualization problem"

http://lua-users.org/wiki/LuaVirtualization

Basically, the string type is too baked into Lua to allow drop-in replacements.

Although I'd say the primary motive for string methods is not
polymorphism but convenient laziness ;)

> Hmm, interesting! I didn't think of that ... Now only the issue with
> sandboxing remains.

Alas, that metatable is still globally shared per Lua state[1], so it
violates the "Don't mess with other people's code rule"

Now, using something like Lanes allows you to work with multiple
states conveniently - and this kind of thing becomes more attractive.

[1] but, if it was indexed relative to the "thread" - the currently
running coroutine - we would have some more freedom to go wild - or
get really hardass restrictive...