lua-users home
lua-l archive

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


Am 22.11.2013 06:01 schröbte Dirk Laurie:
E.g.

mymod = require "mymod" -- prints a welcome message

If for non-interactive use you want to suppress the message, that
can be done by providing an option, e.g.

mymod = require "mymod" "silently"

Figuring out that your module table *won't* be called with "silently" as an argument and suppressing output in this case requires your module to look into the future. The other way around is easier:

    mymod = require "mymod" "verbose"

... or you could use something like this (requires debug module):

    local function is_interactive()
      if type( debug ) ~= "table" or
         type( debug.getinfo ) ~= "function" then
        return false
      end
      local info, i = debug.getinfo( 2, "S" ), 3
      while info do
        if info.what == "main" and info.short_src == "stdin" then
          return true
        end
        info, i = debug.getinfo( i, "S" ), i+1
      end
      return false
    end

What information do you like in the welcome message? Module name? Author? Version? Summary? List of exported functions? ... ?

Philipp