lua-users home
lua-l archive

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


On Thu, Dec 9, 2010 at 10:46 AM,  <rrt@sc3d.org> wrote:
> I am happy to announce the release of stdlib release 16

Please don't:

  module ("math", package.seeall)
  local _floor = floor
  function floor (n, p)
    local e = 10 ^ (p or 0)
    return _floor (n * e) / e
  end

Aside from the modularity issues of injecting into standard namespaces
(mentioned most recently in [1]), and the pollution of math with
package.seeall (e.g. security issues of math.debug appearing inside
sandboxes), this may also impact numerical code performance by causing
all floor calls in a program to unnecessarily go through the above
operations if any module in the program loads stdlib.

If you like, I suggest this:

  -- math_ext.lua
  local M = {}
  for k,v in pairs(math) do M[k] = v end
  function M.floor(n, p) ..... end
  return M

  -- test.lua
  local math = require "math_ext"
  print(math.floor(math.pi, 2))


[1] http://lua-users.org/lists/lua-l/2010-12/msg00212.html