Lua 5.3: integers, bitwise operators, and a basic UTF-8 library
lua.org
lua.org
A little bit OT here but I always think the situation of lua 5.1/5.2 is just like python2/python3. E.g. lots of applications' embedded lua version is still 5.1 (Lightroom, Max 7, WoW?, Codea on iPad). Some packages like Metalua still only run on 5.1.
Lua literally runs everywhere with implementations that run in or on any platform you are currently using (Java, C#, C/C++, Javascript).
Can you please elaborate (or give some link)?
There are a range of compiler tricks that can make boxed math go fast as well.
"Using 64 bit integers all-over will definitely hurt tight loops on 32 bit machines -- narrowing number ranges is very tricky for the compiler. Also, the fact that int64_t is neither a subset nor a superset of a double is worrying. This kills various optimizations and may give surprising results even in simple mixed-type expressions."
video: https://www.youtube.com/watch?v=bjqNK1jA77M
slides: http://www.inf.puc-rio.br/~roberto/talks/ws2014.pdf
The main advantages of adding integers to Lua are:
* For some things you need 2^64 bits, not just 2^53 (file handles, crypto algorithms with bitwise operations, etc)
* Some embedded systems don't have hardware support for floating point (you could compile Lua with integers instead of double but it was very hacky)
* It simplifies the C API. There are some things in the API and various internals in the implementation that benefit from separating integers and floating point numbers.
Sometimes the hardware/OS/drivers/something else is buggy with floats...
I once designed a game that needed integers for some things, and implemented it with Lua, on Windows machines it started to sometimes give VERY WRONG results (even in very short operations, like reporting that 5+5 == 11 or that 8+2 == 9, those are actual errors, not just short numbers to make typing easier).
Later I found out it had to do with a infamous directX bug, where it changed the settings of the floating point units without permission, and sometimes this resulted into really, really, really funky floating point math, meaning that all math made with Lua in those cases maybe could be completely wrong.
Back then when I found this (The issue, not the reason for it), many Lua devs kept telling me I as crazy or a troll, thankfully one guy in freenode.net #lua had the brilliance to tell me to check if it was the DX issue (and it was... the issue don't happened on Linux or OSX)
Until you divide them by three.
There is a time and a place for integer arithmetic. You could get there with liberal use of truncation, but it reads better as native integer arithmetic.
The slope is slippery, time to resist or embrace native complex, rationals, and quaternions… I only stop the list here because it is as much as I've ever used in real world code.
Do write some good test cases though that compare to someone else's implementation. I accidentally wrote my multiplication backwards and didn't catch it for a long time. I just had a vague feeling that something was wrong every time I wrote rotation code.
Linden Scripting Language even provides quarternions conversion with llEuler2Rot, llRot2Euler and llAxisAngle2Rot. See: http://wiki.secondlife.com/wiki/Quaternion for an introduction.
So quaternions are useful for 3d games, and games are a hot topic for Lua. But its not required, that complex numbers or quarternions are part of base language. See: http://lua-users.org/wiki/ComplexNumbers - thats easy to implement with Lua prototyping.
There are two main reasons: - Modern systems are now 64-bit and they sometimes have APIs that demand 64-bit integers. (For example, file APIs that deal in bytes like fread).
- Small, embedded systems that are 32-bit or less, which don't have good floating point hardware and are RAM constrained. Lua 5.3 now means double no longer has to be used to represent 32-bit integers. Instead integers can be directly (avoiding floating point for performance) and floating point sizes can be reduced down to float instead of double (reducing the size of internal objects).
Roberto Ierusalimschy (Lua creator) has given several talks about why bring integers to Lua 5.3. https://www.youtube.com/watch?v=bjqNK1jA77M
A somewhat related thing(not addressed by this yet) is about Electric Imp, who had to switch to a different language from lua(which they started with). The reason was that they needed to store values for an LED array, and the only data type is tables, and all integers are 32 bit.
Not sure but they might have used user defined types, with the arrays stuff being done in C, might have been easier.
Thinking about Redis bitmaps, they could be very useful when available in the scripting context/
As a library, there were edge cases such as what if you used the number as floating point or what happens with 64-bit.
Now with integers, bitwise operations can be put directly into the language instead as a library.
It does not seem impossible to me to add functionality to a browser to accept some other language to run. What you're talking about is how hard it would be to convince JS developers to stop using it. But no one is talking about that.
Believe it or not, a long time ago, Javascript was actually the less bad option in web scripting. IE used language="vbscript" to allow web scripting in VBScript, which, AFAIK, was the only other language that became popular for scripting web pages.
The extra overhead that supporting an additional language implies with hybrid websites (even if you disregard JS completely, external code like advertisements would introduce it). People can claim that the overhead is negligible with today's hardware, but this is not always the case, especially when you are trying to get as much performance as possible for a web-based game engine.
We should be working hard to kill Flash and Java completely from the web, substituting them with modern and standard web technologies.
I don't mind an obscure corporate website requiring their employees to install Flash or Java, but I do mind being bombarded with "please install Flash with Mc Affee unless you opt-out", because we are too lazy to display video without Flash.
A better alternative to have Lua in the browser (at least in my opinion) is to support Mozilla's asm.js initiative, and compile Lua to LLVM/JS.
If you're worried about performance, why are you advocating asm.js? That's always going to be less performant than direct browser support for a language.
> We should be working hard to kill Flash and Java completely from the web, substituting them with modern and standard web technologies.
The JVM (on which Java is only the most prominent of many languages) is standard and modern. So was Dart. So is Lua.
TL;DR: You won't get Lua support in your favorite browser if you don't build web projects with Lua today, and you can only use Lua via asm.js today.
non-TL;DR: because of 3 reasons:
1) JS is not going away, and you are not going to convince the main browser vendors to use Lua, this makes Lua via asm.js the only realistic way to use Lua in any browser today.
2) VMs like OdinMonkey use a different strategy when they detect the "use asm" pragma, and this allows Lua via asm.js to run faster than JavaScript, but this only applies to Firefox.
3a) In order to convince browser vendors to take Lua seriously, Lua has to be massively adopted in the web.
3b) In order to help Lua to become massively adopted in the web, it needs to run fast everywhere, not just in Mozilla's browsers.
3c) In order to help Lua to run fast everywhere, the teams behind other JavaScript VMs (V8, JSCore, Chakra, etc.) need to be convinced that the web needs asm.js.
3d) In order to convince the people of other JS VMs, we need to build more projects which use asm.js.
--
> > We should be working hard to kill Flash and Java completely from the web, substituting them with modern and standard web technologies.
> The JVM (on which Java is only the most prominent of many languages) is standard and modern. So was Dart. So is Lua.
The JVM, nor Dart, nor Lua are web standards, also, I expect from you to not be nitpicking my comment, I was referring to the frontend (ie. applets / flash player).
What does that even mean? They're standardized in exactly the same way as ECMAScript. Every standard isn't a web standard until it is. Javascript wasn't any kind of standard at all when Netscape introduced it, nor even when Microsoft adopted it too.
Of course this is only a proof-of-concept which just runs a Lua REPL in the browser. I wonder if it is possible (and if so, how hard it is) to make the browser run <script language="lua"></script> code.
In regards to actually doing the DOM work, craig barnes is doing great work over with lua-gumbo: https://github.com/craigbarnes/lua-gumbo
Code that does it: https://github.com/kripken/lua.vm.js/blob/master/src/lua.js#...
I stopped using Turbo Pascal, C++ or TCL, because backwards incompatibility. A language implementation like Turbo Pascal, C++ or TCL is outside of my application scope. Any operating system distribution update could break compilation of my code anytime. It did and I decided for my self to avoid those language.
But its a total different case with Lua, or my own DataFace microframework, because those are inside of my application. The Lua interpreter code is not some library coming from operting system distribution, but a shared lib, I ship with my code, and a source code tree within my own application. My old applications do not need to care, if something in Lua 5.3 breaks them. But I can investigate the new features for next application.
Roberto addressed the idea of a infinite number type, but it has a lot of downsides which are very un-Lua like, i.e. complicated, slow (no real hardware), and interoperability problems with the C API (which is very important to Lua).
video: https://www.youtube.com/watch?v=bjqNK1jA77M slides: http://www.inf.puc-rio.br/~roberto/talks/ws2014.pdf