lua-users home
lua-l archive

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


Dave Nichols a écrit :
I think its a brilliant trick too and should be supported.
AFAICT its a one line change to luaL_loadfile in lauxlib.c, from this:

  if (c == '#') {  /* Unix exec. file? */
    lf.extraline = 1;
    while ((c = getc(lf.f)) != EOF && c != '\n') ;  /* skip first line */
    if (c == '\n') c = getc(lf.f);
  }

to this:

  if (c == '#' || c == '@') {  /* Unix exec. file or windows batch file? */
    lf.extraline = 1;
    while ((c = getc(lf.f)) != EOF && c != '\n') ;  /* skip first line */
    if (c == '\n') c = getc(lf.f);
  }


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Asko Kauppi
Sent: 17 September 2006 07:27
To: Lua list
Subject: Re: {Spam?} Re: Lua scripts made into executable on win32
(smalladdition request)

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 ---------

A: Because it is hard to read!

Q: Why top-posting is bad?

...

As Rici pointed out, it is so easy to associate .lua extension in Windows, I don't see the point. In old Win9x, you still have to call Lua.exe on the command line, because it is Dos that only accepts some extensions as exe. But in NT/2k/XP, no problem. I even wrote a small program that parses the shbang line to find which version of Lua to run. I don't use it much... :-)

If that is for camouflaging .lua as .bat or .cmd, well it is a bit peculiar, not worth of changing the official Lua for that.


Bonus:

REGEDIT4

[HKEY_CLASSES_ROOT\.lua]
@="luafile"

[HKEY_CLASSES_ROOT\luafile]
@="Lua Script"
"AlwaysShowExt"=""

[HKEY_CLASSES_ROOT\luafile\DefaultIcon]
@="C:\\PrgCmdLine\\Lua.exe,-1"

[HKEY_CLASSES_ROOT\luafile\shell\open\command]
@="\"C:\\PrgCmdLine\\Lua.exe\" \"%1\" %*"


--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --