lainchan / λ
Lua
Anonymous · 2017-04-17 12:16
Is Lua worth learning for web development? I have little to no experience in programming and i know python is usually recommended as a begginer language but I want something simple and small and something I can have a total command over.
I might want to use it later for other things and not just web development.
Chan Siu Ming · 2017-04-17 12:22
openresty is the most popular way to do lua on the server side. it's a distribution of nginx coupled with luajit and has a large variety of extension modules.
Liet Kynes · 2017-04-17 12:48
I quite like lapis http://leafo.net/lapis/
It takes care of a lot of the boiler plate usually associated with getting openresty running with anything more than the basics.
Turner · 2017-04-17 13:01
>>414
Javascript implementations are faster than Lua and prototype object orientation is a lot better than how tables are used in Lua to fake OO
Lua only became famous as a game scripting language and thats still only what its used for
Masami Eiri · 2017-04-17 13:12
>>417
this is false. luajit is faster than spidermonkey or v8 because it can compile lua into more efficient and concise sequences of instructions. remember lua as a whole is simpler than javascript.
lua is also growing in use as an extension language for many programs like vim.
Turner · 2017-04-17 14:34
>>417 LuaJIT is way faster, what are you talking about?
JARGON · 2017-04-17 16:29
>>414
Hey OP.
I personally wouldn't recommend using Lua for webdev. I think it could be an interesting experience/challenge, but only after you've got some more programming experience.
The reason I'm arguing that is because Lua was designed, first and foremost, as an embeddable language. As other anons have mentioned, Lua's most popular use case has been game engine scripting. This is not to say that you *cannnot* webdev in Lua -- sure you can, but you'd need to set up a few things first, and this requires some experience, which I'm assuming you don't have.
Just stick with Python. Python is going to be much simpler to set up and run, and will have much better "documentation" and guides for you. Javascript should be fine, too -- just expect to be criticized for it. (Node.JS receives a ton of hate from the internet -- some of it is justified, some of it isn't. At the end of the day, it really doesn't matter, as long as it allows you to get soykaf done.)
How about this: set up a tiny web server with Python, then try and do the same project with Lua. Let us know how it goes!
JARGON · 2017-04-17 17:21
>>428
Can an entire site be done with JS?
And yeah you're right I should stick with python.
push · 2017-04-17 18:45
Any language is as good as any other for web development, once you understand how it all works. Hint: It's much easier than you might first think.
I suggest you pick up something inspired by Ruby's Sinatra first, because it's an easy way to get comfortable with the concepts.
Then I suggest you play with curl a lot, and look up a middleware similar to Ruby's Rack or Clojure's Ring in your language of choice, so you can see what it all boils down too.
You can probably do it all in Python.
>>433
>Can an entire site be done with JS?
Node lets you use JS for the server as well, but unless you're looking to get a job soon I suggest you stay away from it, if you can help it.
Dujour · 2017-04-17 22:46
>>418
>this is false. luajit is faster than spidermonkey or v8
its not, neither regular Lua or luajit is as fast as these js implementations
>because it can compile lua into more efficient and concise sequences of instructions.
luajit is a side project and not even part of the regular Lua implementation, it is hardly even used because it is not faster than the regular Lua implementation
>remember lua as a whole is simpler than javascript.
its not, even if it was it wouldnt make it faster
There are also new scripting languages like Crystal and Julia which are much faster than both js and Lua
JARGON · 2017-04-17 23:44
>>433
>Can an entire site be done with JS?
Yeah! In the past, Javascript interpreters/VMs only existed within browsers, right? Like, literally, to execute Javascript code, you had to open a browser and access something like "Advanced > Dev Tools > Javascript terminal". So, Javascript was only used for front-end web development. This changed "recently", however, when NodeJS was created.
NodeJS basically took that terminal out of the browser, filled in the gaps (so NodeJS can interact with eg. the hard drive, which wouldn't normally allowed from within a browser), and released it as a "standalone Javascript terminal." So now, you can execute Javascript code "natively", AND you can interact with your computer's actual resources, such as your hard drive, sockets, your screen, keyboard/mouse, etc. It's a full fledged programming environment now, and not only some "web browser scripting tool."
The hatred I mentioned earlier emerges primarily (IMO) from the fact that a ton of front-end web devs suddenly decided to give NodeJS a try, because... "it's the same language, right? Back-end can't be that hard!"
So a bunch of people with inadequate skills started developing tools, libraries and even entire sites that run entirely on Javascript. Their code is terrible and unsustainable, and the ecosystem is absolutely horrifying. To give you some perspective, there was a library (AN ENTIRE LIBRARY) that added padding to text. Thousands of people downloaded and used it -- fuarrrking THOUSANDS -- until one day, the creator of the library disabled it (for personal reasons), and hundreds of sites stopped working. Literally. Don't believe me? Read for yourself.
https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
With that being said, however, it's only the Javascript "ecosystem" that is bad IMO. The language itself is pretty neat and can teach you plenty about programming. Furthermore, its performance will be more than enough for just about every project you decide to build right now, and there is ton of support for it online (because, you know, front-end devs swarmed StackOverflow when they started handling things like files and streams and sockets and stuff.).
Maybe you'll see an anon or two criticize my opinion, and that's fine -- as long as we keep it civil, such discussions can be a very constructive and informative, especially for someone like you, who's learning about all this stuff. It's valuable to see both sides of the coin, and I'll be damned if JS doesn't trigger THAT kind of discussion.
HELIOS · 2017-04-18 00:34
>luajit is a side project and not even part of the regular Lua implementation, it is hardly even used because it is not faster than the regular Lua implementation
Wait what, can you back that information up? I have always been told that luajit was faster than lua
Leto Atreides I · 2017-04-18 01:04
>>454
I dont have that information handy, almost no one uses luajit, that should be proof enough
Unsigned · 2017-04-18 13:09
>>449
>>456
You're full of soykaf.
>it is not faster than the regular Lua implementation
It is way faster than the regular Lua implementation.
http://luajit.org/performance.html
>neither regular Lua or luajit is as fast as these js implementations
It is just as fast, if not faster, than V8 on most benchmarks.
http://stackoverflow.com/questions/2588071/is-luajit-really-faster-than-every-other-jit-ed-dynamic-languages
Though the performance improvement obviously won't matter much if you're embedding it and using it only for small functions.
>almost no one uses luajit
That's because almost no one uses Lua as their main language for development, it's usually embedded as a scripting language for a bigger application written in C or what have you.
You could argue that LuaJIT is dead. There has not been much development going on since the main developer of the project left, and unless somebody steps up and starts pouring a lot of work into the project, it will wither away.
It still remains one of the (if not the) fastest JIT compilers for a dynamic language around.
Agent Richard Gill · 2017-06-09 18:11
>>417
Lua tables and JS prototypes are extremely similar and are actually the key features that make them such great host extension languages.
Do you even know what you're talking about
Sabo Engle · 2017-06-09 19:25
>>1704
It's just a troll who knew nothing about Lua. Ignore them.
dictionary · 2017-06-09 23:05
>>1704
>Lua tables and JS prototypes are extremely similar and are actually the key features that make them such great host extension languages.
I don't know much about Lua, asides from the basic data type being a hash table or similarly behaving object; would you explain why Lua tables are similar and how this makes it a good extension language? I can recall other extension languages that have this datatype, but don't use it centrally.
>>1707
>It's just a troll who knew nothing about Lua. Ignore them.
I'm not them, but wouldn't it be fair to write that JavaScript has received a great deal of optimization in the past few years that may make it faster than Lua? I've never seen a comparison of the performance between these two languages.
It's important to take into consideration that Lua does operate over an optimized virtual machine specifically suited for it, however. I've read some concerning the machine code-level optimizations that have been made to it, involving keeping certain state in registers constantly, for speed, but can't currently find this.
I'm also unaware of some other common uses for Lua. Do you use Lua for other such tasks? If so, what?
null · 2017-06-10 08:58
>>1708
>I'm not them, but wouldn't it be fair to write that JavaScript has received a great deal of optimization in the past few years that may make it faster than Lua? I've never seen a comparison of the performance between these two languages.
Again, refer to >>473. LuaJIT is about as good, if not better, than any Javascript engine out there.
>I'm also unaware of some other common uses for Lua. Do you use Lua for other such tasks? If so, what?
Nope, Lua lacks a standard library and nobody's cared enough to give it something like Node. I wouldn't start a new project in pure Lua because I'd have to write half of what I need myself, and I don't like the language enough to bother.
>would you explain why Lua tables are similar and how this makes it a good extension language?
I think what makes it a good extension language is its very solid C API and the relative speed and small size of its main implementation. If you pull in Lua, you will have to read just a few hundred LoC.
Backus · 2017-06-10 22:09
>>1708
> I'm also unaware of some other common uses for Lua. Do you use Lua for other such tasks? If so, what?
Luajit is heavily used in machine learning with http://torch.ch, it's probably the fastest machine learning system out there. Facebook ported ResNet over from Caffe recently https://github.com/facebook/fb.resnet.torch
Meddler · 2017-06-10 23:55
>but I want something simple and small and something I can have a total command over.
>I might want to use it later for other things and not just web development.
sounds like python is a perfect fit.
maybe lua is too though.
quote · 2017-06-14 20:59
>>473
>You could argue that LuaJIT is dead
I have no insider information but there have been releases since May so it isn't yet. To be honest, I doubt it will die very easily, because >>1715 .
Knuth · 2017-06-14 22:35
>>1801
Oh, so somebody took over as maintainer? That's great, I hope they keep it going.
Agent Jones · 2017-11-10 05:45
>>414
Lua is worth learning so that you can use the computers in the computercraft mod for minecraft to simulate the ARPANET, recreate SSH ingame, and talk to other lainons by joining up to the minecraft server and sending pointlessly encrypted messages to eachother.
cdr · 2017-11-10 08:12
My only xp with Lua has been with gamedev using Love2d. From what I gathered, it's a pleasant simple language with some subtle power behind it. Never heard of it being used for webdev.
If you're looking for something simple and small that is LIKE lua but is good for web dev (or at least people use it for webdev), look into ruby.
Hououin Kyouma · 2017-11-11 10:45
>>4889
>>4891
Ruby made a splash in the web world by pioneering a new style of web framework with Ruby on Rails which other languages have since copied. It is sad that this success effectively killed the reputation of the language in the English speaking world like you 2 gentlemen pointed out.
While the West moved from Perl to Python, Japan moved from Perl to Ruby. Ruby is a far better designed language than Python. It has an object system that is actually integrated into the language and not just bolted on the side with dicts. And the overall feel of the language is basically Lisp without the awkward syntax. But Rails came along and now it's only considered as a dumb web language like PHP.
I love Ruby but you guys are right. I can't go to a Ruby meetup without being surrounded by mouth breathing knuckle dragging web people.
Just another Random Lainon · 2017-11-12 10:59
>>417
Lua tables are prototype OO
↑ · 2017-11-12 11:13
>>1713
I'm not sure it's fair to say 'lua has no standard library'; the official standardlib is smaller than other languages but libraries like Penlight and LuaFileSystem could be considered 'unofficial' standard libs.
These days there are Lua libraries for almost anything Python has a library for, there's just less choice than with Python.
McCarthy · 2017-11-12 14:36
>>4910
For me this is the only cons of Lua. It has no "batteries included" as much as Python.
Anamika · 2017-11-13 08:36
>>4911
You should check out Penlight, it's basically the python stdlib ported to Lua.
I think by having these things outside the core, the language is less likely to accumulate cruft over the years and get locked into a weird way of doing things.
It also means you don't have to include features you aren't using in space constrained environments.
Gyula Kovacs · 2017-11-14 06:27
>>417
>Lua only became famous as a game scripting language and thats still only what its used for
Lua is used to serve webpages¹, to create plugins²³, text editors⁴ and even mail clients⁵. I dislike the language but you can't say that it's only used for games.
¹: https://blog.cloudflare.com/pushing-nginx-to-its-limit-with-lua/
²: https://github.com/neovim/neovim/pull/4411
³: http://elinks.or.cz/documentation/html/manual.html-chunked/ch14.html
⁴: https://foicica.com/textadept/
⁵: https://lumail.org/
list · 2017-11-14 09:39
>>4949
>Lua only became famous as a game scripting language and thats still only what its used for
Could we fix that by saying Lua is only used by users to extend applications that are written in other languages? It's not intended to be used as a language on its own or a replacement to something like Python.
>Lua nginx
This might not be clear to everyone at first blush, this is about extending the web server itself by writing Lua instead of C. It's not "web development".