lua-users home
lua-l archive

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


There’s a third motivation for using Lua/C modules in browser – there’s an existing library implemented in C, no compatible JS variant and/or you don’t wanna rewrite it.

I’ve mentioned LPeg. Yes, there’s LuLPeg, but “mostly compatible with LPeg” is not very convincing for me.

I know it’s tough task, I’m just asking about possibilities we have.

To add some context, I’m thinking about running Lua in browser for demo purposes (e.g. CLI utility you can try in a browser before installing) more than writing web applications in Lua.

Thanks,
Jakub

> On 27. Jul 2017, at 1:07, Hisham <h@hisham.hm> wrote:
> 
> On 26 July 2017 at 19:42, Jakub Jirutka <jakub@jirutka.cz> wrote:
>> I know about LuLPeg, but I’ve used LPeg just as an example. I’m interesting
>> about general support of Lua/C modules. Is it currently somehow possible?
> 
> The motivations one uses Lua/C modules are either for extra speed, or
> for interfacing with existing libraries. For the first motivation,
> going through Emscripten and then the Lua/C API and run the whole
> thing on top of JS would probably be slower than writing a module
> directly in Lua; the approach for critical speed would be to write
> something in JavaScript instead and go through Fengari's Lua/JS API.
> For the second motivation, I suppose most existing libraries one would
> want to interact with in a browser would be existing JS libraries, and
> not C libraries. For a lot of C libraries, it wouldn't make sense to
> port them into the browser, but for those that can be compiled into JS
> libraries via Emscripten, I suppose one can bind them to Lua via the
> Lua/JS API, but the binding module needs to be rewritten (from C to
> JS).
> 
> The linked article mentions that the approach of compiling Lua C code
> into the browser via Emscripten makes you end up with two garbage
> collectors. For this reason, simply building both a C library and its
> Lua/C binding with Emscripten and expecting them to work with Fengari
> doesn't sound feasible. But the approach I described above, in which
> the C library is compiled into JS and a Lua/JS binding is
> custom-written for it, does (unless I'm missing something—the Fengari
> authors will surely correct me if that's the case).
> 
> -- Hisham
> 
>> Jakub
>> 
>> On 27. Jul 2017, at 0:23, Charles Heywood <vandor2012@gmail.com> wrote:
>> 
>> I'm not sure about using Emscripten, but there is LuLPeg which is mostly
>> compatible with LPeg - enough that MoonScript can be compiled with it.
>> 
>> On Wed, Jul 26, 2017 at 1:10 PM Jakub Jirutka <jakub@jirutka.cz> wrote:
>>> 
>>> Hi Benoit,
>>> 
>>> Fengari is really awesome project, thank you and daurnimator very much for
>>> it!
>>> 
>>> I have one question. How about Lua/C modules? Is it currently possible to
>>> compile e.g. LPeg into JS using Emscripten and use with Fengari?
>>> 
>>> Jakub
>>> 
>>> On 26. Jul 2017, at 14:34, Benoit Giannangeli <giann008@gmail.com> wrote:
>>> 
>>> Hi there,
>>> 
>>> Fengari is a project me and daurnimator have been working on the past
>>> months which aims to bring Lua to the browser.
>>> 
>>> Here is the introductory article for it:
>>> http://lua.space/webdev/why-we-rewrote-lua-in-js
>>> 
>>> --
>>> Benoit Giannangeli
>>> 
>>> https://github.com/giann
>>> 
>>> 
>> --
>> --
>> Ryan <vandor2012@gmail.com>
>> Software Developer / System Administrator
>> https://hashbang.sh
>> 
>> 
>