How to run scripts on Lua?

Post Reply
User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

How to run scripts on Lua?

by Andrey01 » Post

I`ve started to learn Lua at first time today. But i don`t know how to run a file with scripts. In one book it says it needs to call the comand % lua <filename>, but it doesn`t work.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to run scripts on Lua?

by sofar » Post

Andrey01 wrote:I`ve started to learn Lua at first time today. But i don`t know how to run a file with scripts. In one book it says it needs to call the comand % lua <filename>, but it doesn`t work.
Minetest includes lua internally, but the `lua` command isn't part of that. You likely need to install a standalone `lua` package first before that command becomes available.

User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: How to run scripts on Lua?

by Andrey01 » Post

sofar wrote:
Andrey01 wrote:I`ve started to learn Lua at first time today. But i don`t know how to run a file with scripts. In one book it says it needs to call the comand % lua <filename>, but it doesn`t work.
Minetest includes lua internally, but the `lua` command isn't part of that. You likely need to install a standalone `lua` package first before that command becomes available.
Now i can run scripts. It appears i don`t need '%' symbol for comand 'lua <filename'. I tried other way to run ones is to use function dofile() in console.

lightseer
Member
Posts: 132
Joined: Mon Jan 23, 2017 16:18

Re: How to run scripts on Lua?

by lightseer » Post

Lua is an interpreted language that is not intended to run by itself. It is similar to Python, which is intended to run by itself. Lua is intended to run as part of other programs such as: Gimp or minetest. It expects to find itself inside of another program. That is, if someone includes Lua in their program its to give you access to the internal functions of their program. Python can be used in the same way, but Lua is made for this almost exlusively. You can run Lua from the commandline, but its not really meant for that.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to run scripts on Lua?

by sofar » Post

lightseer wrote:but its not really meant for that.
That's just silly. Interpreted languages are just as easily usable outside of another program as they are as an embedded modding language.

Code: Select all

echo -e '#!/usr/bin/env lua\nprint("hello")\n' > test.lua && chmod 755 test.lua && ./test.lua
The above demonstrates that lua could just be used like a shell script or a python script, without embedding.

Lua was designed to be small, and Lua's small size makes it *excellent* for embedding, but that does not logically translate that Lua was designed to be embedded. It also makes for an excellent scripting language by itself just fine.

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to run scripts on Lua?

by Linuxdirk » Post

lightseer wrote:Lua is an interpreted language that is not intended to run by itself. It is similar to Python, which is intended to run by itself. Lua is intended to run as part of other programs such as: Gimp or minetest. It expects to find itself inside of another program. That is, if someone includes Lua in their program its to give you access to the internal functions of their program. Python can be used in the same way, but Lua is made for this almost exlusively. You can run Lua from the commandline, but its not really meant for that.
I've never read so much nonsense in one single post.

lightseer
Member
Posts: 132
Joined: Mon Jan 23, 2017 16:18

Re: How to run scripts on Lua?

by lightseer » Post

sofar wrote:
lightseer wrote:but its not really meant for that.
That's just silly. Interpreted languages are just as easily usable outside of another program as they are as an embedded modding language.

Code: Select all

echo -e '#!/usr/bin/env lua\nprint("hello")\n' > test.lua && chmod 755 test.lua && ./test.lua
The above demonstrates that lua could just be used like a shell script or a python script, without embedding.

Lua was designed to be small, and Lua's small size makes it *excellent* for embedding, but that does not logically translate that Lua was designed to be embedded. It also makes for an excellent scripting language by itself just fine.
Sounds like I misspoke. It is usually found embedded in things.

lightseer
Member
Posts: 132
Joined: Mon Jan 23, 2017 16:18

Re: How to run scripts on Lua?

by lightseer » Post

From the Lua documentation page: https://www.lua.org/semish94.html This is "The first paper describing Lua." It is described as "A language for extending applications."

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests