[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A Lua script and a Bash script in one file
- From: Michael Wolf <miwo@...>
- Date: Tue, 8 May 2012 12:42:23 +0200
2012/5/8 Michael Wolf <miwo@gmx.at>:
> 2012/5/8 Egor Skriptunoff <egor.skriptunoff@gmail.com>:
>>> A Bash script that's also a Lua script!
>>
>> That's funny!
>> The same thing for .bat-files in Windows:
>>
>> rem = 'This is .BAT-file and .lua-script' --[[
>> @echo This is .BAT-file
>> @lua52.exe %0
>> @goto end
>> ]]
>> print 'This is Lua script'
>> --[[
>> :end
>> @rem ]]
>>
>
> Nice idea!
>
> If you replcae "@goto end" with "exit /B" you dont need the trailing
> goto which looks a bit nicer
>
> rem = 'This is .BAT-file and .lua-script' --[[
> @echo This is .BAT-file
> @lua52.exe %0
> @exit /B
> ]]
> print 'This is Lua script'
As I really like the idea but don't like that the first line gets
printed to the console I added a check in skipcoment.
If the first character is a @ it gets ignored. and as a lusfile
starting with an @ is not valid i think it's save.
--- src\lauxlib.c Tue May 08 12:05:10 2012
+++ lauxlib.c Tue May 08 12:04:32 2012
@@ -619,6 +619,9 @@
while ((c = getc(lf->f)) != EOF && c != '\n') ; /* skip first line */
*cp = getc(lf->f); /* skip end-of-line */
return 1; /* there was a comment */
+ }else if(c=='@'){ /* used for luafile as a batchfile in windows */
+ *cp = getc(lf->f);/* ignore 1st character */
+ return 0;
}
else return 0; /* no comment */
}
Now I can use the following lua as a batchfile which does not output
the rem line:
@rem =--[[
@echo This is .BAT-file
@lua52.exe %0
@exit /B
]]
print 'This is Lua script'