lua-users home
lua-l archive

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


On Mon, Jul 4, 2011 at 5:50 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> Lua does not have warnings. Note that to add warnings to Lua is not
> to add some 'printf's; we need some way to return warnings from 'load'.
> (Multiple returns?) I do not think it is worth the complexity...

Pierre-Yves suggestion along the printf approach might work--i.e.
writing warnings globally either to stderr or perhaps something like
print() since print is for debugging and can be more safely overridden
to redirect warning output to some other location.  I don't know if we
need informational warnings to be uniquely associated with each load
(as errors are).

2011/7/4 Pierre-Yves Gérardy <pygy79@gmail.com>:
> That functionality would better be implemented as a small library that
> would be loaded only during the porting effort.

-- warnings.lua
local debug = require 'debug'
local env = {}
for k,v in pairs(_G) do env[k] = v end
env.module = function(...)
  io.stderr:write('WARNING: module function is deprecated\n',
debug.traceback(), '\n')
  return module(...) -- [*] problem
end
return env

-- test.lua
_ENV = require "warnings"
module "test"  -- displays warning; does not raise error
print 'ok'

Although in this case of functions like module that query stack
levels, Lua has a forwarding problem [1-2], so this code won't work
entirely as advertised.

[1] http://lua-users.org/lists/lua-l/2010-01/msg01255.html
[2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm