lua-users home
lua-l archive

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



He might not want to have the files as .lua, but to comeurflauge (what's the right spelling?? :( ) them as .bat or .cmd.

I have to say, that TRICK is soooo brilliant (didn't know it can be done!) that it should be supported. Just as a tribute to the brilliant ways people deal with Windows being what it is. :)

-asko


Rici Lake kirjoitti 17.9.2006 kello 6.11:

Wouldn't it be simpler to use something similar to the instructions
for associating the perl interpreter with perl scripts, found
in this irritatingly long URL:
http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/faq/Windows/ ActivePerl-Winfaq4.html#How_do_I_associate_Perl_scripts_

On 16-Sep-06, at 8:12 PM, JAST wrote:

Lua scripts made into executable on win32 (small
addition request)


any lua script, can be made in to batch file,
example, a script:

---------- LUASCRIPT.LUA ---------

print("hello universe!")
for k,v in ipairs(arg) print(k,v) end

---------- LUASCRIPT.LUA ---------

the script above can be made into batchfile by
adding shell commands (see below)
lua will ignore those command because they are
commented.
the command "goto =goto" will just do nothing

---------- LUASCRIPT.BAT ---------

goto =goto

print("hello universe!")
for k,v in ipairs(arg) print(k,v) end

--[[
:=goto
@echo off
set f=%0
	if exist "%f%" goto run
set f=%0.bat
	if exist "%f%" goto run
set f=%~f0
	if exist "%f%" goto run
set f=%~$PATH:0
	if exist "%f%" goto run
for %%d in (%path%) do if exist "%%d\%0"     set
f=%%d\%0
	if exist "%f%" goto run
for %%d in (%path%) do if exist "%%d\%0.bat" set
f=%%d\%0.bat
	if exist "%f%" goto run	
	
:run
	lua.exe "%f%" %1 %2 %3 %4 %5 %6 %7 %8 %9
::]]

---------- LUASCRIPT.BAT ---------


after adding this shell commands:
you can just type:

C:\> luascript.bat arg1 arg2 arg3

or

C:\> luascript arg1 arg2 arg3


BUT there is a small tiny little microscopic
problem.
it outputs the shell command "goto =goto" too!

C:\>luascript arg1 arg2 arg3
C:\>goto =goto
hello universe!
1       arg1
2       arg2
3       arg3
C:\>_

this is a large giagantic huge  problem if your
script is
putting information to stdout!

my addition request for lua interpreter is,
since,
Lua, to allow the use of Lua as a script
interpreter in Unix systems,
the stand-alone interpreter skips the first line
of a chunk if it starts with #.
why not the stand-alone interpreter skips the
first
 line of a chunk if it starts with '#' or '@'.

'@' becuase a shell command in Windows prefix
with '@'
prevents the interpreter from displaying the
command onscreen.
so the first line of the script will be:

@goto =goto

'=goto' is an ugly label maybe this is more ok:

@goto batchcmd

the file will now look like this

---------- LUASCRIPT.BAT ---------

@goto batchcmd

print("hello universe!")
for k,v in ipairs(arg) print(k,v) end

--[[
:batchcmd
@echo off
set f=%0
	if exist "%f%" goto run
set f=%0.bat
	if exist "%f%" goto run
set f=%~f0
	if exist "%f%" goto run
set f=%~$PATH:0
	if exist "%f%" goto run
for %%d in (%path%) do if exist "%%d\%0"     set
f=%%d\%0
	if exist "%f%" goto run
for %%d in (%path%) do if exist "%%d\%0.bat" set
f=%%d\%0.bat
	if exist "%f%" goto run	
	
:run
	lua.exe "%f%" %1 %2 %3 %4 %5 %6 %7 %8 %9
::]]

---------- LUASCRIPT.BAT ---------

please!



if lua has an option like the '-S' in perl (look
for programfile using PATH environment variable)
i think its possible to trim the script to this

---------- LUASCRIPT.BAT ---------

@goto batchcmd

print("hello universe!")
for k,v in ipairs(arg) print(k,v) end

--[[
:batchcmd
@lua.exe -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
]]

---------- LUASCRIPT.BAT ---------


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com