lua-users home
lua-l archive

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


On 8 May 2012 11:42, Michael Wolf <miwo@gmx.at> wrote:
> 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.

This is not necessary, with Lua 5.2 you can (ab)use labels to avoid
printing the first line:

  ::start:: --[[ This is .BAT-file and .lua-script
  @echo This is .BAT-file
  @lua52.exe %0 %*
  @exit /B
  ]]
  print 'This is Lua script'

Cheers,

Tomek