lua-users home
lua-l archive

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

On Mon, Jul 4, 2011 at 3:40 PM, Luiz Henrique de Figueiredo
<> wrote:
> Lua 5.2.0 (beta-rc5) is now available [...]
>        - clarifications between 'deprecated' and 'removed'

This way of removing functions might not be ideal:

  $ make ansi
  $ ./src/lua
  Lua 5.2.0 (beta)  Copyright (C) 1994-2011, PUC-Rio
  > io.popen'ls'
  stdin:1: 'popen' not supported
  stack traceback:
  	[C]: in function 'popen'
  	stdin:1: in main chunk
  	[C]: in ?
  > setfenv(function()end, {})
  stdin:1: deprecated function
  stack traceback:
  	[C]: in function 'setfenv'
  	stdin:1: in main chunk
  	[C]: in ?

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).  However, the
experience with JavaScript has been that capability detection is
preferred over version detection.  For example, Opera traditionally
lied and said it was Internet Explorer to avoid false negatives, but
when you really did want to differentiate them then it got confusing

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