lua-users home
lua-l archive

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



On 11-Jun-07, at 7:40 PM, Francisco Sant'anna wrote:

Hello,

When creating a module sometimes is also useful to run it from the command line as a standalone application.
How to discover the invoke method?
Here's how I'm doing now:

-- checks if the module is being 'required' or executed
local STANDALONE = (debug.getinfo(1).short_src == (arg and arg[0]))
module ((...) or 'default_name')
...
if STANDALONE then
    whatever()
end

You can use the following:

local STANDALONE = type(package.loaded[...]) ~= "userdata"

There's an explanation of how it works in this message:
<http://lua-users.org/lists/lua-l/2007-02/msg00125.html>