lua-users home
lua-l archive

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


I just want to add a comment here. The is a Lua implementation called Luerl which runs in Erlang/Elixir systems and while it can of course be called from Erlang/Elixir also fits into their concurrency model so you can run many Lua evaluations concurrently in the systems. I have examples using Luerl where you can use Lua to program the logic of literally thousands of spaceships all running concurrently.

Robert


On Wed, 16 Mar 2022 at 08:26, Marc Balmer <marc@msys.ch> wrote:


Am 16.03.2022 um 06:06 schrieb Srijan Paul <srijannr1@gmail.com>:

You are correct in your understanding of the term "embeddable". A programming language by itself isn't very useful.  We want to embed it in larger programs like game engines, web servers, text editors, image processing software etc. to do useful things with it.

Lua is readily embeddable owing to it's minimal interface that it exposes via the C API.

The Lua interpreter is written in C, and is made available as a static library that can be used just like any other regular C library. It makes sense if you consider that Lua is simply a program that takes text (the Lua program) as input and produces side effects like output to a console, or generating a result from the computation.

Once the interpreter has been initialised, it runs in an infinite loop until it's done executing the program.

The embedding program may provide C functions to the interpreter that take Lua values and return Lua values. The interpreter knows that whenever a Lua program references a function named "foo", it is supposed to pause execution, call the c function bound with that name, and return the result produced by it to the Lua side again.

You might find this blog post useful if you're looking to embed Lua yourself:


On Wed, Mar 16, 2022, 9:14 AM admin@saptasindhu.website <admin@saptasindhu.website> wrote:
I understand that Lua is a scripting language, and hence has an interpreter, most probably with an in-built compiler (like Perl).

I fail to understand what is meant by Lua being embeddable.
Does it mean that the Lua interpreter (which is written in C) can be included in a larger C program?
If yes, does that mean the larger C program can then run Lua scripts while the larger C program is running?
If yes again, how do those Lua scripts being called from the larger C program get access to that C program's functions?
For example, I can understand that a stand-alone interpreter for a scripting language would have a systems programming interface which exposes the low-level routines (like POSIX or WinAPI) to be used by that scripting language.
But, I cannot understand how a embeddable Lua interpreter could be useful?

Best regards.
 


There is an ongoing series of articles on the subject on https://marcbalmer.ch/ (Integrating Lua with C), which will eventually culminate in the Lua Integration Guide on https://lua.msys.ch/

- mb