I 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 da…
Lua 5.4.0 beta
51–60 of 103 posts
Re: Lua 5.4.0 beta
#52People that use lua, what do you use it for and why did you pick lua?
It’s a simple, but powerful language that uses basically two features (functions and hashmaps) to implement everything. Ex: script files are implicitly functions. Global variables are in a hashmap. Semantically it is very much JavaScript without all the surprises. Semi-technical users (artists and designers) can figure it out and go on to make surprisingly powerful features.
The binary code is small and fast. The standard library is small and most of it can be removed easily. Parsing source to bytecode is quick. Loading bytecode is very fast.
It is easy to embed. It’s easy to contain it’s memory allocations in an arena. It’s easy to restrict what it can and cannot do. It’s easy to interface with C/C++. It’s extremely portable.
Re: Lua 5.4.0 beta
#53People that use lua, what do you use it for and why did you pick lua?
Re: Lua 5.4.0 beta
#54I 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 da…
I 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/
Re: Lua 5.4.0 beta
#55Wish they could improve the language syntax. It's so unnecessarily verbose. Moonscript did a good job improving Lua.
It sounds small, but with callback heavy or embedded DSL code it very quickly adds up.
Re: Lua 5.4.0 beta
#56Earlier quoted context omitted.
> 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/ and https://duktape.org/ . The latter seems oddly familia…
My 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 t…
There was a while that I wanted use this to design a programming-based video game, where simulated agents worked in real time. Most of the programming games I have seen use a fixed timeout, and kill any scripts still running after that time. What I was thinking was to instead have the script constantly running, and any slow scripts continue running on the next frame (e.g. all players get 100 opcodes per frame).
Re: Lua 5.4.0 beta
#57Main 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-t…
>- 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?
Re: Lua 5.4.0 beta
#58People that use lua, what do you use it for and why did you pick lua?
Re: Lua 5.4.0 beta
#59Earlier quoted context omitted.
The performance difference is pretty stunning. https://luajit.org/performance_x86.html
Indeed. 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.
For a pure Lua comparison LuaJIT is typically going to beat Lua by a large margin. For code that can be JIT compiled you might see ~10x performance improvements and for code that doesn't you might still see around a ~2x improvement because the LuaJIT interpreter is written in hand-crafted assembly language (PUC-Lua sticks to portable and standards-compliant C90).
But things get a bit more complicated if you add foreign C code into the mix. Under LuaJIT, the JIT compiled code that uses the LuaJIT FFI interface is the fastest, but interpreted code using the FFI is slower than interpreted code using the traditional Lua-C interface, and can even be slower than PUC-Lua using the traditional Lua-C interface. This means that when you are using LuaJIT you need to be very careful to make sure that your code is the sort of code that can be JIT compiled. If you hit a "not yet implemented" feature you can have a big performance degradation.
------
Nevertheless, Lua 5.4 has brought significant performance improvements compared to Lua 5.3, specially in integer operations (including for loops). Another big change was that the `#` is now faster. For example, on my machine the following loop runs in 1.96 seconds in Lua 5.3, in 1.26 seconds under LuaJIT, and in 0.96 seconds in Lua 5.4
local a = {}
for i = 1, 1e7 do
a[#a +1] = i
end
print(#a)
The new generational garbage collector is also a very big improvement. I've measured a 1.5x speedup on some GC-dominated workloads, where the final result was that Lua 5.4 would even edge out LuaJIT, which is still using the old incremental collector.Re: Lua 5.4.0 beta
#60People that use lua, what do you use it for and why did you pick lua?
It's the language used in my digital signage service for the Raspberry Pi (see https://info-beamer.com & https://info-beamer.com/doc/info-beamer ). The main reason to choose Lua back when I started was the there were no serious alternatives for: * Easy embedding. Compared to Python and ruby which I looked at back then, Lua is so much simpler. * Fairly easy to learn for users. After all, the complete syntax is one pag…