12 ms·
Lua 5.4.0 beta
- dottrap 7y agoMain changes - new generational mode for garbage collection - to-be-closed variables - const variables - userdata can have multiple user values - new implementation for math.random - warning system - debug information about function arguments and returns - new semantics for the integer 'for' loop - optional 'init' argument to 'string.gmatch' - new functions 'lua_resetthread' and 'coroutine.close' - coersions string-to-number moved to the string library - allocation function allowed to fail when shrinking a memory block - new format '%p' in 'string.format' - utf8 library accepts codepoints up to 2^31
- i_feel_great 7y agoWhat would you use coroutine.close () for?
- tyingq 7y agoClosing a looping coroutine from outside the loop?
- yanex 7y agoI suppose, just to close to-be-closed variables declared inside a sleeping coroutine.
- i_feel_great 7y agoWhy not let the function in the coroutine exit normally? Maybe I should go read the docs. Killing a coroutine from the outside looks like poor design/bad idea.
- ufo 7y agoLua 5.4 has a new feature called to-be-closed variables. It is intended to allow for deterministic freeing of resources, even in the face of possible runtime exceptions. (Sort of like RAII in C++). The canonical example is that you can mark a variable holding a file handle as to-be-closed and then as soon as you exit the variable's scope the file gets automatically closed (including if exit early due to break, return, or error). But what is supposed to happen if you are inside a coroutine and pause the execution before reaching the end of the scope, and never resume again? If there are any to-be-closed variables their destructors will never run! Or they might only run after the containing coroutine gets garbage collected, which is not a timely solution. To cover this situation, Lua 5.4 introduced a new coroutine.close function that kills a paused coroutine and runs the destructors of any to-be-closed variables inside it, if there were any.
- ufo 7y agoThe interpreter also got many performance improvements under the hood.
- akklesed 7y ago>- utf8 library accepts codepoints up to 2^31 Interesting. Didn't Unicode restrict UTF-8 to allow encoding only 21 bits? Does it mean that it can now do 6 byte UTF-8 encodings? What kind of restrictions did it have before?
- zamadatix 7y agoComparing the documentation seems to verify this easily: - https://www.lua.org/manual/5.3/manual.html#6.5 https://www.lua.org/manual/5.3/manual.html#6.5 - https://www.lua.org/work/doc/manual.html#6.5 https://www.lua.org/work/doc/manual.html#6.5
- kzrdude 7y agoI don't see how this is a good change, it's like, back to 1994 utf-8
- sdegutis 7y ago> coersions string-to-number moved to the string library Does this mean + can finally be used for string concatenation and .. disabled as an opt-in C flag?
- fullstop 7y agoIt's nice and all, but I'll be over here using LuaJIT.
- sam_lowry_ 7y agowhy?
- lytedev 7y agoPresumably speed?
- cosarara 7y agoBecause it's fast.
- tyingq 7y agoThe performance difference is pretty stunning. https://luajit.org/performance_x86.html https://luajit.org/performance_x86.html
- Fnoord 7y agoThat is comparing with 5.1.5, not 5.3 or 5.4 beta. (The default of comparing x86-32 also does not make sense to me, YMMV.)
- tyingq 7y agoI couldn't find a way to deep link to the x64 numbers, but they aren't significantly different. Hopefully they update it with a more current Lua version.
- johnisgood 7y agoIndeed. Mike Pall blows them out of the water single-handedly. I wonder if Lua developers have learnt anything from him with respect to performance. I would like to see how Lua 5.4.0 would perform in comparison.
- nomadluap 7y agoI'm looking through the new reference manual and there doesn't seem to be any mention of const variables, or any mention of how the new to-be-closed variables work. Do you just define the __close metamethod and lua takes care of the rest?
- dottrap 7y agoI haven't tried them yet, but in the work reference manual, look at: 3.3.7 – Local Declarations and 3.3.8 – To-be-closed Variables I think the syntax use is: local x <const> = 5 local filename <const> = "/etc/fstab" local fh <close> = io.open(filename, "r")
- ecmascript 7y agoPeople that use lua, what do you use it for and why did you pick lua?
- Doctor_Fegg 7y agoMy OpenStreetMap tag processing pipeline: OSRM, osm2pgsql and tilemaker all allow you to write tag-mangling scripts in Lua.
- cobbzilla 7y agoIt’s great for embedded scripts in Redis.
- dnoberon 7y agoDo you have an example use case you could share?
- krapp 7y agoI use it as a configuration and data language, mostly for building APIs for other libraries (like SDL2). The syntax is simple and clean, like JSON but without the most commonly cited warts (no requirement to quote keys, and comments are allowed.) The VM is lightweight enough that including it in an application is practically inconsequential. I like its modular syntax as well. There are also bindings for just about every language out there, making Lua code more easily portable and embeddable. It's not without its flaws as a language but to me, it's better suited as a config language than TOML, YAML or XML for most use cases where you don't actually need their complexity, or JSON if you're not on the web.
- ammmir 7y agoFor KVdb [1], my managed key-value store database, I opted to integrate Lua as a scripting language instead of JavaScript because it felt super lightweight and the syntax is easy to learn in a few hours for even newbies. I'll probably end up adding JavaScript, too, since most developers know it, but there is a simplicity about Lua that I haven't seen in many other somewhat popular languages. [1] https://kvdb.io/docs/scripting https://kvdb.io/docs/scripting
- alberth 7y agoJust recall that Lua versioning schema allows for breaking changes to point releases. This has been both great for Lua as a Lua and one of its biggest challenges. It's allowed the language be constantly refined and tweaked; however, at the expense that it's super common for applications to complete break when upgraded to a point release. https://www.lua.org/versions.html https://www.lua.org/versions.html
- unbendable 7y agoWe use lua 5.3 on an embedded Platform for scripting and it has been a roller coaster ride. Not a fun one, unfortunately. You want luasocket? The stable one is not compatible with 5.3. Packages are sometimes outdated (for years no updates) and there is no replacement. The lua point releases have breaking changes. The source code itself is a macro hell which is hard to debug. And the code is not very readable. The documentation lacks for some topics of you use the c api. I tried to implement some scheduling for c and lua threads. Oh and one thing if you must use Windows... you better quit right away. I had to help my co worker Installing it with luarocks and it is a mess. to be fair it was easy on my Ubuntu machine. The thing is lua on embedded has no rival. but god did it cost me some nerves.
- dividuum 7y ago> The documentation lacks for some topics of you use the c api. I'm surprised to hear this. I'm doing a lot of Lua and I always thought the documentation is very succinct and complete. I really curious when issues you ran into. > The thing is lua on embedded has no rival. but god did it cost me some nerves. You might take a look at https://bellard.org/quickjs/ https://bellard.org/quickjs/ and https://duktape.org/ https://duktape.org/. The latter seems oddly familiar if you've worked with the Lua C API.
- mikepurvis 7y agoMy info might be a bit out of date, but something that surprised me when I looked into it was how little control I had over the embedded lua interpreter from my outer app. I basically had to hand it control by calling lua_pcall, and either wait for a result or manage a timeout from another thread. I expected to be able to do things like tell Lua to run for X milliseconds or Y opcodes or whatever, but it didn't seem that anything like this existed. So perhaps my disappointment with the documentation was really just disappointment that the implementation wasn't set up to do what I wanted in the way I wanted to do it. But in the course of coming to this realization, I also found the documentation frustrating and opaque.
- 7y ago
- mikorym 7y agoDoes this release influence LuaTex? Or rather, maybe, how is it going with LuaTex? I've previously opted for LuaTex rather than "base" Tex or XeLaTex and I'm at the point where I'd happily stick to LuaTex and also learn some of it's more technical aspects.
- daurnimator 7y agoThis is only a beta release; final could still be a year away.....
- bbmario 7y agoWish they could improve the language syntax. It's so unnecessarily verbose. Moonscript did a good job improving Lua.
- chc4 7y agoMost of it I'm pretty okay with. The one big pain point is lambda definitions: you have to do `function(x) print(x) end` each time, instead of `\x. print(x)` or something. It sounds small, but with callback heavy or embedded DSL code it very quickly adds up.
- jdance 7y agoI love lua syntax, its the only language I feel I actually dont have to look up syntax when I return to it a year later. Its just stupid simple, and that has a big value for me. Maybe Java < 8 also .. also pretty simple but very verbose :)
- neuland 7y agoI use Lua via OpenResty / lua-nginx-module and in personal C projects for plugins and scripting. Some of these seem useful, like utf8 support and const variables. For the multiple user data values feature, I've always found lightuserdata more useful than userdata, because it's not often that you need just one bunch of simple memory that can be freed without any other work. Rather, I almost always have more complex data, such as things that need manual cleanup like sockets, handles, etc. Or, the structure has pointers to other things that must also be cleaned up. What I'd like instead is the ability to pass a destructor callback to `lua_pushlightuserdata` so that it get's called when the pointer falls off the stack. I don't use Lua threads or coroutines currently, so I don't have much to add there. What I do wish is that there were a way to clone or pass objects from one lua state to another to support parallelism. Basically, I'm thinking of it like the work Eric Snow is doing on subinterpreters in Python. Passing values (by copying, no shared memory) between lua instances. One use case I had is loading a plugin that you then want to run multiple instances of in parallel with different arguments. Ideally, you wouldn't have to load the plugin multiple times (therefore calling the module level code multiple times). So I'd like to copy the entire lua state and then run each one with different arguments. There's no userdata, coroutines, or lua threads, so I don't have to worry about things that aren't possible to copy. I got as far as looking into how to copy functions and then got busy with other things and stopped. Is there anyone else out there trying to introspect Lua function structures and copy all the opcodes, upvalues, etc?
- dividuum 7y agoI think that's what Lua Lanes if for. Haven't used it myself, but the descriptions sounds exactly like what you're looking for: http://lualanes.github.io/lanes/ http://lualanes.github.io/lanes/
- neuland 7y agoWow, thanks for sharing! Not sure why I didn't find this when I was looking. It does look like a very good match to my use case. I'll have to try it out.
- astatine 7y agoWe use Lua 5.1 in an embedded system and it works great. We use only a few standard libraries and have several dozen of our custom libraries exposed as Lua APIs. Predictable memory usage is really good. It's several years since we picked the then current version of Lua and have had no reason to upgrade. What would be the motivations to upgrade to a new Lua version on an embedded system where there is a working version?
- dividuum 7y agoI don't think there's any reason to upgrade unless some of your dependencies require a higher version and backporting is more expensive that porting over all your existing code. Since it sounds like you expose libraries with your own code and you have full control over your ecosystem, I don't think it makes sense to upgrade. At least in my project I see no reason to switch away from LuaJIT (so ~5.1/5.2). It works perfectly well and I don't see why that would change.
- ufo 7y agoIn an embedded system sometimes the "leave it alone" factor outweighs the new features. Anyway, you can find a summary of changes since 5.1 here: https://www.lua.org/versions.html https://www.lua.org/versions.html One of the biggest changes was the introduction of 64 bit integers in Lua 5.3 Perhaps my favorite little change is that you don't need to type = in the repl to print an expression anymore.
- greggman2 7y agoThis is probably not the right place to ask but ..., given that Lua is commently embedded in games, anyone know of a sandboxed version? I'd love to provide a scripting language for user mods to a game but I'd like as much as possible to not have to trust the mods.
- yanex 7y agoYou can choose what parts of the standard library scripts allowed to use. Just exclude os/debug libraries, and that's it. Newer versions of the Programming in Lua book contain detailed instructions.
- orthoxerox 7y agoLua supports sandboxing via its _G variable, i.e., implicit global scope. When you call a script, you can pass it a custom _G.
- sdegutis 7y agoLua is extremely sandboxable from hosting C. Just only add modules, functions and features you want added. Makes good use of the C preprocessor flags too. But also check out QuickJS as a neat alternative. But it probably doesn’t compare in speed to LuaJIT which is mostly the flavor used I think.
- yanex 7y agoIt seems that quite a lot of people use Lua. I liked the language, it's tiny and well-made. However, I wasn't happy about the tooling support. IDE plugins, documentation generators, lint checkers – all of this seem abandoned. Is there any similar language (embeddable, good C interoperability) with better tooling besides JavaScript?
- sdegutis 7y agoQuickJS is a Lua-like JS interpreter if you’re ok with JS.
- yanex 7y agoWell, I'm not a big fan of JavaScript :) I like the direction ECMAScript is going. However, the clumsy things are going to stay because of backward compatibility. Also, QuickJS is a good initiative, but I afraid it's not production-ready yet. It doesn't even have versioning and/or changelog.
- sdegutis 7y agoThe top of https://bellard.org/quickjs/ https://bellard.org/quickjs/ is the changelog and each release is versioned by date. Nobody's a fan of the quirks of JS, but you can almost entirely ignore them and only use the good parts.
- yanex 7y agoWell, I won't call "New release" / "New release" a changelog. It's simply not a log of changes.
- legends2k 7y ago[Nim][1] seems to be a potential option. [1]: https://nim-lang.org/ https://nim-lang.org/
- yanex 7y ago
- nikolay 7y agoUnfortunately, we only care about LuaJIT, which is lagging behind.