lua-users home
lua-l archive

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


The present situation is that you can when building Lua disable
automatic conversion between numbers and strings. All it takes
a line in a section of src/Makefile set aside for user settings.

MYCFLAGS= -DLUA_NOCVTN2S -DLUA_NOCVTS2N

As befits an experimental feature, this is not in the Manual but
it has been discussed often enough that "everybody" knows it.

There is no direct way to see whether this has been done but it is
easy to check whether `1 .. 2` or `"1"+"2"` is legal. However, there
is no way to switch coercion on or off at runtime. The executable
invoked when you just type 'lua' can behave in one of four possible
ways. Maybe some of us have two or even four executables for the
different settings; I will be impressed.

By the time we reach the next version, quite possibly the feature will
no longer be experimental, therefore documented, and maybe the
default setting will be different from what it is now.

Personally, I compile with

MYCFLAGS= -DLUA_NOCVTS2N

It offers a wide range of benefits. Since the string metatable can be
accessed without the debug library, a clean way to implement a DSL
inside Lua is to use expressions involving strings. especially now
that Lua 5.3 offers so many more operations.

But it is not so easy if you have to worry all the time whether
'str1 ~ str2' might not just decide to xor the bits instead of performing
whatever cute operation you have been using the syntax for. And if
you actually like the present behaviour, you can always supply
a metatable for that.

I can live with -DLUA_NOCVTN2S if I must, but the convenience
of being able to use table.concat on an array of numbers will be
sorely missed, and setting a __concat metamethod for numbers
won't bring it back.