lua-users home
lua-l archive

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


On 04/07/2011 22.19, David Manura wrote:
On Mon, Jul 4, 2011 at 3:40 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br>  wrote:
Lua 5.2.0 (beta-rc5) is now available [...]
        - clarifications between 'deprecated' and 'removed'

This way of removing functions might not be ideal:

I totally agree.

[...]


The reason is that to test whether a function exists, it is not as simple as

   if io.popen then ..... end

Rather, you need to wrap it in a pcall, and in the case of popen you
need to pass some suitable argument that probably will always work
(e.g. "echo").

Alternately, you could test versions (e.g. _VERSION).
[...]

I understand that Lua team maybe intended to warn the user that his version of Lua doesn't support io.popen on his platform, but this seems too much hand-holding to me.

Maybe a stronger emphasis in the manual on checking the existence of popen before using it could be added instead.

For example (emphasis on new text):


"This function is *highly* system dependent and is not available on all platforms. *If you are not sure whether your system supports popen, check its existence explicitly in advance.*"

And if more hand-holding is deemed useful, add a snippet:

if io.popen then
 -- do something
end


The recent discussion about whether string.foo should raise an error
[2] is related to this.

[1] http://www.sitepoint.com/why-browser-sniffing-stinks/
[2] http://lua-users.org/lists/lua-l/2011-06/msg01382.html




-- Lorenzo