[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: proposal: executing modules as scripts
- From: David Manura <dm.lua@...>
- Date: Sun, 2 Sep 2007 01:29:44 +0000 (UTC)
New feature proposal for Lua: Module Execution Proposal
=== Abstract ===
This is a proposal for a new command-line switch (-p) that loads a function with
the given package name via the searchers in package.loaded and then executes
that function as a script, passing the command-line arguments to the function as
arguments.
lua -p modname args
Example:
-- my/app.lua
print("hello", io.read"*a", ...)
local i=0; while arg[i] do print(i, arg[i]); i=i-1 end
$ echo -n 123 | lua -p my.app 3 4 5
hello 123 3 4 5
0 my.app
-1 -p
-2 lua
=== Rationale ===
A typical use of this would be if you have a Lua script installed in the Lua
path (e.g. LUA_PATH) rather than the system PATH, and you want to locate and
execute that script. The script may have a dual use as a module and a
command-line utility. Maybe this is a Lua-based profiler, debugger, code
validator, or macro processor that operates on other Lua code.
lua -p yet.another.debugger mybuggyprogram.lua 3 4 5
lua -p yet.another.preprocessor myprogram.m4 4 5 5
There is precedent here--for example, the "-m" switch in Python:
-m mod : run library module as a script (terminates option list)
-----
The full details and patch for this proposal are available at
http://lua-users.org/wiki/ModuleExecutionProposal
The description currently also suggests a new "loadmodule" function and includes
three related proposals:
- Allow -e to Accept Command Arguments
- New package.find Function
- Detecting Whether Function Loaded via Require
Comments?