lua-users home
lua-l archive

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


If using a variable, luafile in this case, then you should add setlocal to
prevent polluting globals

::lua:: --[[
@setlocal 
@set luafile=%0
@if exist %0.bat set luafile=%0.bat
@lua52.exe %luafile% %*
@exit /b %ERRORLEVEL%
]]
--assert(false)
print 'This is Lua script'
os.exit(2)



> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
> On Behalf Of Michael Wolf
> Sent: dinsdag 8 mei 2012 23:21
> To: Lua mailing list
> Subject: Re: A Lua script and a Bash script in one file
> 
> This solution works good with different calling methods but has 2 more
> problems.
> 1) If the lua script fails the batch wont stop and will interpret each
> line of the lua part.
> 2) The exit code of the lua script is not given back.
> 
> I have following solution which solves booth problems but does not
> look very good.
> Maybe someone with better batch knowledge can shorten it while
> preserving all functionality.
> 
>  ::lua:: --[[
> @set luafile=%0
> @if exist %0.bat set luafile=%0.bat
> @lua52.exe %luafile% %*
> @exit /b %ERRORLEVEL%
> ]]
> --assert(false)
> print 'This is Lua script'
> os.exit(2)
> 
> 2012/5/8 Daurnimator <quae@daurnimator.com>:
> > On 9 May 2012 02:08, Egor Skriptunoff <egor.skriptunoff@gmail.com>
> wrote:
> >> Impressing results!
> >>
> >> One more problem should be solved.  User can enter command line
> >> manually (hello one two three) or can simply double click on the
> file
> >> and full filespec will be placed into command line
> >> ("C:\path\hello.bat").  Both cases should be properly handled.
> >>
> >> ::Lua:: --[[
> >> if exist %0.bat lua52.exe %0.bat %* && exit /b
> >> lua52.exe %0 %* && exit /b
> >> ]]
> >> print 'This is Lua script'
> >
> > Much better is using %~nx0
> > lua52.exe %~nx0 %*
> >