News for hackers. Stuff that matters.
Re:Tables by sdegutis on Wednesday September 12, 2018 @12:12PM (#17970232)
Lua is amazing in that it is very small, portable, and easily embeddable. But aside from those three things, Lua is semantically almost identical to modern JavaScript.

I've embedded both and used them heavily in my various window managers, and these days I personally recommend embedding JavaScript over Lua if possible.

But when a small, portable and lightweight language is needed, there's also Sparkling[1], which is like the best ideas of JavaScript with the minimal footprint and portability of Lua.

[1]: http://h2co3.github.io/sparkling/

Re:Tables by vvanders on Wednesday September 12, 2018 @01:08PM (#17970851)
> Lua is semantically almost identical to modern JavaScript.

Having spent a lot of time looking pretty hard at Lua, LuaJIT, and embeddedable variants of JS(duktape and the like) I think that's a bit of a stretch.

It's pretty trivial to induce JS memory leaks[1] that can be brutal on embedded platforms. We had a prototype project written in JS and Lua, same functionality but hit issues like this pretty often. Like most memory leaks they weren't straightforward to track down as well.

For my money LuaJIT still reigns supreme despite the fact that it's not under active development any more[2].

[1] http://point.davidglasser.net/2013/06/27/surprising-javascri...

[2] https://www.freelists.org/post/luajit/Looking-for-new-LuaJIT...

Re:Tables by zeotroph on Wednesday September 12, 2018 @12:51PM (#17970675)
> Sparkling

All these "Let's do Lua, but right" languages fill me with both hope AND dread. This also shows what Lua could have become if a few more bold decisions were made. But I guess without a large commercial entity behind it, that was inevitable.

Is there list of lua-ish (especially wrt. speed and easy C integration) languages somewhere? I did not know this one for example.

Re:Tables by engineer331 on Wednesday September 12, 2018 @11:16PM (#17975686)
You might want to check out Squirrel[1]. It has some major differences when compared to Lua[2], such as a C-style syntax and true objects, but like Lua is known for easy embedding in C and C++. The Source Engine includes Squirrel as one of its supported scripting languages[3], and it's used in non-gaming applications such as the Code::Blocks IDE.

[1]: http://squirrel-lang.org/

[2]: http://wiki.squirrel-lang.org/mainsite/Wiki/default.aspx/Squ...

[3]: https://developer.valvesoftware.com/wiki/Squirrel

Re:Tables by mingodad on Thursday September 13, 2018 @05:33AM (#17977235)
There is also a squirrel fork SquiLu[1] that add some Lua code (like pattern matching, some stdlib), extend it with string IO, have several extensions (sqlite3, http server, mpdecimal, axtls, curl, ...), accept a subset of Javascript/Java/C/C++, ...

[1]:https://github.com/mingodad/squilu

Re:Tables by wruza on Thursday September 13, 2018 @10:18AM (#17978773)
>almost identical to modern JavaScript

What do you mean by ‘almost’? You cannot have fair separate threads of execution or substitute function’s global environment in javascript, but this is the other way ‘almost’. What features does js have beyond syntactic sugar and second-hand techniques?

Re:Tables by vmsp on Wednesday September 12, 2018 @12:34PM (#17970477)
What JavaScript interpreter do you use for embedding? I know of MuJS [1] but it only supports ES5.

[1] https://mujs.com/

Re:Tables by dividuum on Wednesday September 12, 2018 @06:53PM (#17974247)
There's duktape (https://duktape.org/), which, from skipping over the documentation seems very similar to Lua when it comes to embedding: It also uses the stack based approach. Looks like there's some ES6/7 support.
Re:Tables by sdegutis on Wednesday September 12, 2018 @12:35PM (#17970493)
My JS-embedded apps only target macOS so I use Apple's builtin JavaScriptCore framework.
Re:Tables by nikki93 on Wednesday September 12, 2018 @12:52PM (#17970700)
In my experience LuaJIT in interpreter only mode has better performance than using JSC (you can’t use JIT in JSC either — only WKWebViews can JIT).

(edit: sorry this is regarding iOS)

Re:Tables by sdegutis on Wednesday September 12, 2018 @12:59PM (#17970773)
Maybe, but my use-cases (window manager and other automation stuff) don't really have a strong need for speed or high performance. Mostly it just sits there idle 99% of the time and runs callbacks quicker than the UI that it manipulates is visibly updated.
Re:Tables by nikki93 on Wednesday September 12, 2018 @01:15PM (#17970914)
Yeah I think it does end up boiling down a lot to use cases because the big differences b/w Lua and JS are in availability of libs / integration and perf. In my case I do a lot of 2d graphics where love2d.org is available and perf is important. :) C interop is also really important, and LuaJIT C FFI is waaaaay nicer to use than JSC C API.

I’ve ended up doing a lot of JS with React Native for “app-y” mobile apps though.

Re:Tables by sdegutis on Wednesday September 12, 2018 @01:18PM (#17970937)
If perf is important, I'm surprised you're using Love2d and not just using C++ with SDL and Box2d directly. Afaik Love2d just uses vanilla Lua (and not LuaJIT) which, while faster than similar languages, is still pretty wasteful of cycles when high perf is needed.
Re:Tables by armitron on Wednesday September 12, 2018 @01:42PM (#17971127)
Love2d can use luajit or plain lua.
Re:Tables by nikki93 on Wednesday September 12, 2018 @04:28PM (#17972926)
perf is important but I also want user scriptability (as part of the actual app feature(s)). Love2d uses LuaJIT (it does use the C API to bind its native calls rather than the FFI -- but actually that has better perf when not JIT'ing).