[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What languages could be used to implement the functions to be invoked by Lua?
- From: Albert Krewinkel <albert+lua@...>
- Date: Fri, 18 Sep 2020 19:40:11 +0200
Francisco Olarte writes:
> On Fri, Sep 18, 2020 at 10:59 AM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>> As per the documentation(https://www.lua.org/pil/24.html), which says
>> that[emphasise mine]:
>> At the same time, a program that uses Lua can register new functions
>> in the Lua environment;
>> such functions are implemented in C (or **another language**) and can
>> add facilities that
>> cannot be written directly in Lua.
>> My question is what other languages?
>> Can these functions be implemented in C++? If not, is there any
>> workaround to achieve this goal?
>> If you could give some simple examples, that would be great.
>
> Once compiled, everything is machine code. You only have to worry
> about the calling convention ( where are parameters passed and how are
> values returned ).
I think this omits error handling and language run times, both of which
can be a challenge. E.g., HsLua, a Haskell wrapper around Lua, must be
very careful to handle errors at the language boundary. Assume a Lua
function `pcall`s a Haskell function, which then calls another Lua
function. If that last Lua function errors, then the Haskell runtime
system will be corrupted if we `longjmp` across language boundaries.
See <https://hslua.github.io> for a bit more info.
I believe languages like Rust and Go face similar issues.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124