A way to download and run Lua from a single shell or batch script (also works without a terminal)

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

A way to download and run Lua from a single shell or batch script (also works without a terminal)

Elias Hogstvedt

This is a way of running Lua with one or two mouse clicks on Linux, macOS and Windows. It also supports running properly from the command line. It works by simply downloading the Lua executable with batch or shell from the internet.

I've been using methods similar to this in my own projects for a long time and has proven to be useful in practice. Especially combined with a single line you can run in the terminal to download this one file while it does the rest. I also personally like the idea of having source code all the way.

One small issue I don't know how to solve if the Lua script were to be in a batch file is the first line being "rem =nil BATCH_PROGRAM=[[" followed by "@echo off". This will echo that line when ran from a command line window. Maybe someone figured this out?




Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Albert Chan

On Oct 1, 2018, at 1:32 PM, Elias Hogstvedt <[hidden email]> wrote:

One small issue I don't know how to solve if the Lua script were to be in a batch file is the first line being "rem =nil BATCH_PROGRAM=[[" followed by "@echo off". This will echo that line when ran from a command line window. Maybe someone figured this out?

I still don't know what start.cmd does ...

But can rem =nil  ... replaced by ::line1::  ... ?

Batch file will ignore anything after first :
As a batch label, it will also not echo the line.
Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Elias Hogstvedt
Actually this seems to work on Windows. I was testing your suggestion under Wine which didn't work.

On Mon, Oct 1, 2018 at 9:07 PM Albert Chan <[hidden email]> wrote:

On Oct 1, 2018, at 1:32 PM, Elias Hogstvedt <[hidden email]> wrote:

One small issue I don't know how to solve if the Lua script were to be in a batch file is the first line being "rem =nil BATCH_PROGRAM=[[" followed by "@echo off". This will echo that line when ran from a command line window. Maybe someone figured this out?

I still don't know what start.cmd does ...

But can rem =nil  ... replaced by ::line1::  ... ?

Batch file will ignore anything after first :
As a batch label, it will also not echo the line.
Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Elias Hogstvedt
In reply to this post by Albert Chan
:: is another way of writing comments but comments are also echoed into the terminal so while it works it has the same issue.

::line1:: BATCH_PROGRAM=[[
@echo off
goto:eof
]]

Z:\home\caps>test.bat
Z:\home\caps>::line1:: BATCH_PROGRAM=[[

On Mon, Oct 1, 2018 at 9:07 PM Albert Chan <[hidden email]> wrote:

On Oct 1, 2018, at 1:32 PM, Elias Hogstvedt <[hidden email]> wrote:

One small issue I don't know how to solve if the Lua script were to be in a batch file is the first line being "rem =nil BATCH_PROGRAM=[[" followed by "@echo off". This will echo that line when ran from a command line window. Maybe someone figured this out?

I still don't know what start.cmd does ...

But can rem =nil  ... replaced by ::line1::  ... ?

Batch file will ignore anything after first :
As a batch label, it will also not echo the line.
Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Thijs Schreijer
In reply to this post by Elias Hogstvedt


On 1 Oct 2018, at 19:32, Elias Hogstvedt <[hidden email]> wrote:


This is a way of running Lua with one or two mouse clicks on Linux, macOS and Windows. It also supports running properly from the command line. It works by simply downloading the Lua executable with batch or shell from the internet.

I've been using methods similar to this in my own projects for a long time and has proven to be useful in practice. Especially combined with a single line you can run in the terminal to download this one file while it does the rest. I also personally like the idea of having source code all the way.

One small issue I don't know how to solve if the Lua script were to be in a batch file is the first line being "rem =nil BATCH_PROGRAM=[[" followed by "@echo off". This will echo that line when ran from a command line window. Maybe someone figured this out?


Nice, I knew about the Windows trick, but not the Unix one.

Thijs

Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Egor Skriptunoff-2
In reply to this post by Elias Hogstvedt
On Mon, Oct 1, 2018 at 11:33 PM Elias Hogstvedt <[hidden email]> wrote:
:: is another way of writing comments but comments are also echoed into the terminal so while it works it has the same issue.

::line1:: BATCH_PROGRAM=[[
@echo off
goto:eof
]]

Z:\home\caps>test.bat
Z:\home\caps>::line1:: BATCH_PROGRAM=[[



I'm using DOS command "cls" for clearing the screen :-)
http://lua-users.org/lists/lua-l/2018-07/msg00404.html
Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Albert Chan

On Oct 2, 2018, at 4:12 PM, Egor Skriptunoff <[hidden email]> wrote:

I'm using DOS command "cls" for clearing the screen :-)
http://lua-users.org/lists/lua-l/2018-07/msg00404.html

I just add a simple 2 lines patch to luaL_loadfile()
If a file start with @, Lua skip it all, to <ESC> (ascii 27)
Example:

@echo off
echo Running batch file test.bat
echo Loading Lua to run itself ...
Lua test.bat
exit/b

<ESC>
print("Lua code start here ...")

The patch made the Lua DLL code smaller, and Lua run faster. Weird ...
Batch file also look cleaner, without the hackish ::_:: --[[ stuff





Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Elias Hogstvedt
In reply to this post by Egor Skriptunoff-2
I wouldn't like it if a utility was clearing with my history :) Also "@echo" off still emits a newline.

For fun I've been researching a bit on how to download files on older versions of Windows and ended up using windows script host as fallback for Windows 2000 and XP. One issue I found was that they don't support https out of box so you'd have to host the files somewhere that supports http.

I should also try some old or minimal Linux distro as well to see if it works.

On Tue, Oct 2, 2018 at 10:13 PM Egor Skriptunoff <[hidden email]> wrote:
On Mon, Oct 1, 2018 at 11:33 PM Elias Hogstvedt <[hidden email]> wrote:
:: is another way of writing comments but comments are also echoed into the terminal so while it works it has the same issue.

::line1:: BATCH_PROGRAM=[[
@echo off
goto:eof
]]

Z:\home\caps>test.bat
Z:\home\caps>::line1:: BATCH_PROGRAM=[[



I'm using DOS command "cls" for clearing the screen :-)
http://lua-users.org/lists/lua-l/2018-07/msg00404.html
Reply | Threaded
Open this post in threaded view
|

Re: A way to download and run Lua from a single shell or batch script (also works without a terminal)

Elias Hogstvedt
In reply to this post by Albert Chan
That's neat. I wish I could do something with the shebang (like #echo off would work)  

However you could technically remove the silly syntax and lua code and just call:DownloadFIle "https://www.foobar.com/main.lua" "main.lua" and run it from the batch file.

On Tue, Oct 2, 2018 at 11:10 PM Albert Chan <[hidden email]> wrote:

On Oct 2, 2018, at 4:12 PM, Egor Skriptunoff <[hidden email]> wrote:

I'm using DOS command "cls" for clearing the screen :-)
http://lua-users.org/lists/lua-l/2018-07/msg00404.html

I just add a simple 2 lines patch to luaL_loadfile()
If a file start with @, Lua skip it all, to <ESC> (ascii 27)
Example:

@echo off
echo Running batch file test.bat
echo Loading Lua to run itself ...
Lua test.bat
exit/b

<ESC>
print("Lua code start here ...")

The patch made the Lua DLL code smaller, and Lua run faster. Weird ...
Batch file also look cleaner, without the hackish ::_:: --[[ stuff