lainchan / λ
Lua Programming language
RickNMorty · 2021-05-30 23:03
Is Lua actually worth any thing as a standalone programming language?
What can you tell me about it and which learning resources do you recommend?
Is it relatively popular? Outside of gamdev and plugins, etc...
Ender · 2021-05-31 10:52
>>26027
There's some cool Lua stuff, like Löve2D and TIC-80 (https://love2d.org/ and https://tic80.com/). The upscaling tool, waifu2x (http://waifu2x.udp.jp/), is written in Lua. There's definitely people using it as a standalone language, but it makes more sense to me to regard it as mostly a language to embed into larger projects. And if I had to use Lua for something, I would definitely try https://fennel-lang.org/ instead.
Torvalds · 2021-05-31 14:20
>>26027
I just want to learn Lua beacuse AwesomeWM
Anonymous · 2021-06-01 07:40
im not a programmer but since ive been using linux for such a long time i feel like i need to know a little bit of programming. im learning lua now. its nice so far. im using the Learning Lua 4th Edition and Beginning Lua Programming books. im switching between the two when i get bored with the other. 4th edition is faster and more interesting. Beginning Lua is longer and much more detailed. Id use 4th edition and do the exercises. Use Beginning Lua as a reference for when you need more info about something.
>>26037
ive never tried a lisp before. might look into it
Lady 3Jane.. · 2021-06-01 15:26
>>26027
>Is Lua actually worth any thing as a standalone programming language?
It is a very fine scripting language if you just want to write small useful things and don't want to mess with complexities of something like python or javascript.
>What can you tell me about it and which learning resources do you recommend?
It is very simple to write and very simple to get started with. If you know any other language you can just sit down and start writing code looking at existing codebase and consulting with documentation if in doubt. As for learning resources documentation seems sufficient; since language is simple there is not that much
you can read it all in a couple of hours.
>Is it relatively popular? Outside of gamdev and plugins, etc...
Relatively. At least there are standalone software projects written in it. Library ecosystem is somewhat lacking compared to something like python, but you will be fine most of the time
Junko Enoshima · 2021-06-02 06:46
>>26037
Waifu2x is a very cool project indeed, thanks for sharing lainon
Knuth · 2021-06-03 13:40
>>26027
i'm thinking of learning it too, i keep skirting around the basics of languages and need to actually deep dive into one and i remember using lua in the early 2010's so it's kinda familiar
i heard it's well optimized, is that true?
Dujour · 2021-06-05 18:04
Lua's not really designed to be a standalone language. Its supposed to be embeded in programs written in lower level language like C.
John Titor · 2021-06-06 22:03
>What can you tell me about it
Lua is soykaf.
Just is.
Worse than python.
Unknown · 2021-06-07 04:05
>>26132
Do you have any objective justification for this whatsoever?
Jens Hansen · 2021-06-07 16:50
How does lua compare to python as a scripting language?
John Titor · 2021-06-07 17:55
>>26149
everything in python is an object that uses a special form of pass-by-reference with those objects. Python allows for neat abstractions with this as well as generators and a couple other neat things.
In Lua everything is a value in a table of some set of types, it's a lot faster (sometimes faster than C) but making objects, tables, and managing them is a bit trickier (but far more flexible).
I recommend giving both a try and seeing which you like. Lua imo is a great config and embedded language.
⍕ · 2021-06-07 19:04
>>26150
Thats p much it, sometimes i like to think lua is the c of scripting languages.
What annoys me is that fact that in base lua you cant list files in a directory.
Otherwise its perfectly usable for whatever, it even supports a good amount of functional programming.
Unspecified · 2021-06-07 20:22
>What annoys me is that fact that in base lua you cant list files in a directory
Kek. Is there a workaround or a common practice to solve this, something with C API?
string · 2021-06-07 20:35
>>26155
LuaFilesystem and LuaPosix are two libraries that may help.
Six · 2021-06-08 06:19
I use awesomeWM which uses lua to great effect. I have complicated window rules and functionality that would be harder to get in other WMs like xmonad. Partly because Lua is so simple and well designed. I never had to learn any lua to edit my config, any understanding of programming and you are good to go. I've been using awesome for years and just now I'm learning Lua for a project. I don't consider myself a programmer but I am able to do real tasks without much effort using Lua.
Roy Batty · 2021-06-08 08:36
Those are some of the things I made with Lua:
1. A small script to draw the lorenz attractor with the help of gnuplot. I even posted the code on lainchan a while back.
2. A 2.5D FPP game engine using LuaLove.
3. A script that generated packets with random data and sent them using tcp/ip to one of the systems my old company made to help with testing.
As with other languages you can make anything you want with it. It's just the mater of trying. The only true limit I see is "would it scale and would it be fast enought". I wouldn't make a server with just Lau or a full 3D game not because you can't but rather because there are better options for this.
Joey · 2021-06-08 08:41
>>26169
Oh and I forgot to mention, there is Lau Torch - a machine learning framework for Lau.
Tank · 2021-06-08 16:27
Some malware used to compromise machines as part of a ddos botnet was written in Lua: https://blog.malwaremustdie.org/2016/09/mmd-0057-2016-new-elf-botnet-linuxluabot.html
Molly Millions · 2021-06-26 13:08
>>26027
Lua is a very good language but you'll obviously need to go out of your way to use it just because C/Javascript/C++/Java/and python (unfortunately) are way more common for way more things.
>>26149
Python is an object oriented language and everything works in terms of object hell. There are times and places for that. Most of my experience has been people using Python for imperative programming but also that's because those people have been academics and academics love Python and academics are also usually not very good programmers, they just want to import a bunch of libraries and then run like 10 or 20 lines at a time in a Jupyter Notebook for whatever research paper they're working on this bactun. It's fair and I get why people use it and I don't blame them but I really think Lua's design was much better planned ahead, unlike JS or Python, which have kinda absorbed every wise idea some half asleep intern cooked up in two weeks at Enron. English speakers do not really use Lua to get day to day soykaf done unless they've drank the cool-aid.
>>26153
Lua is much safer about memory and way more standardized than C. Performance/optimization wise tho ig that makes sense. I'm really crossing my fingers that Taobao keeps their LuaJIT fork alive because afaik there is only one dude alive who knows how the fuarrrk it works and he got bored with it and is doing other soykaf now.
>>26172
CIA uses Lua.
>>26037
Openresty for web dev is very neat and could use more attention, and off that there's Lapis, if you're like me and not very good at programming lol.
>>26109
Lua was designed in 1993 by the Pontifical Catholic University of Rio de Janeiro in collaboration with Brazil's state oil company to create a language that non programmers could easily learn and then use to extend existing applications. It's important to keep in context that the line between an "application" and a virtualized operating system was much less blurry back then. Lua is a just fine language for many modern software development projects and is even used in hardware stuff like with NodeMCU or drivers for NetBSD (which seems kinda batshit to me and I don't trust that but ig it's a "Proceed with caution, not our fault if you fuarrrk up past here" kind of thing.
In the good timeline where David Lynch got to direct Episode VI people use Lua everywhere people use Javscript in our universe.
dup · 2021-06-26 14:10
>>26387
In a good timeline SW would not even be a thing.
McCarthy · 2021-06-28 07:34
>>26389
>In a good timeline SW would not even be a thing.
... Star Wars? I guess. I too celebrate 9/11 and despise everything which was not made by a monolingual Japanese (sincerely I'm over 51% serious)
>>26387
>JS or Python, which have kinda absorbed every wise idea some half asleep intern cooked up in two weeks at Enron.
yeah but that is precisely the difference between a language that is not niche and one that is. even Lua is a sell out, by the way. oh how do I know? the word "class" lights up when I type it*
none of you have any right to complain after killing Tcl
*this actually isn't true
Sabo Engle · 2021-06-28 12:16
>>26406
>I too celebrate 9/11 and despise everything which was not made by a monolingual Japanese
I don't. I just dislike SW and all the "geeks" that are part of its fanbase.
Tyrell Wellick · 2021-06-28 15:03
>>26406
Just because 9/11 was awesome doesn't mean you get to be a weirdo about other soykaf smdh
Iverson · 2021-06-28 15:36
>>26406
Why do you celebrate 9/11?
Morpheus · 2021-06-28 18:12
>>26421
underdog syndrome
Marly Krushkhova · 2021-06-28 22:13
>>26425
you think the jews are the underdogs?
nil · 2021-06-29 01:25
Tcl was created to be embedded inside of C programs to allow scriptability (which is the same thing that Lua is designed for). However, over the course of time, Tcl programmers began to favor the reverse approach: extending, rather than embedding.
https://wiki.tcl-lang.org/page/Extending+Tcl
This means writing the program itself in the scripting language, to begin with, and then extending it using C as needed (nowadays you'd use SWIG for this). You declare subroutines in the scripting language and call them as if they were part of the scripting "side", but actually, they're implemented in C for performance gains, etc.. It's a nice approach because dynamic scripting languages are easier to debug interactively, which is what you want during an initial implementation phase.
Is there a similar trend in Lua? I've only ever heard of embedding Lua, but I'm sure the extension approach has been used as well with it.
Cypher · 2021-06-29 01:31
>>26436
forgot to post this link, it's actually the one I had in mind since it goes over the extending vs. embedding debate explicitly:
https://wiki.tcl-lang.org/page/Why+adding+Tcl+calls+to+a+C%2FC%2B%2B+application+is+a+bad+idea
>>26434
>6 pages
very impressive for the amount of features the language has IMO
Koos van der Merwe · 2021-06-29 01:43
>>26434
You think George Bush is Jewish?
Nemissa · 2021-06-30 03:28
I know that prosody.im is written in Lua and extended with C. Its a really good XMPP server. There is a fosdem talk about it from 2016 if you want to hear about using Lua as your project's main language. No huge problems with it btw, mainly just not as many modules as python. Normal stuff when using a semi-niche language.
Trinity · 2021-07-23 09:27
>>26453
xmpp still uses xml :(
Zhora · 2021-10-21 18:00
>Is Lua actually worth any thing as a standalone programming language?
Scripting languages are actual garbage induced from a broken OS (UN*X). Their entire purpose is to (poorly, and insecurely) parse UN*X crap to pipe around.
Pulse · 2021-10-21 19:04
>>28104
>Scripting languages are actual garbage induced from a broken OS (UN*X). Their entire purpose is to (poorly, and insecurely) parse UN*X crap to pipe around.
How do you explain their presence on Windows?
Anamika · 2021-11-01 14:24
>>26040
>I just want to learn Lua beacuse AwesomeWM
Take the PIL: https://www.lua.org/pil/contents.html
sage · 2021-11-20 19:12
>>26040
https://arcan-fe.com/
Awesome is alright but kind of boring
Ric · 2021-12-26 21:23
The Language seems to have a bad reputation ("Arrays start at 1"). A quick glance over the reference manual will hopefully clear up these misconceptions. As other people in this thread have already said, it is meant to be used within other languages. This is not necessarily true. I personally use it as is and gradually rewrite to C when I have a working example to avoid wasting time on the latter. As for popularity, I haven't really seen it being used anywhere other than Neovim and vis, for that matter. Using it as a replacement for shell scripts is not worth it IMHO, since it has poor support for piping, and by that I mean that you'll have to popen() everytime you want to use an external command. Write bindings if you want to get real work done. You'll be pretty much on your own using a semi-niche language like this, however.
Roger Pollack · 2021-12-26 21:48
>>29181
starting from 1 is better
Just another Random Lainon · 2021-12-26 21:53
>>29181
>>29183
Arrays should start at 0, other indexed data structures at 1.
Lua is not wrong at starting them at 1 but only at calling them arrays, they are in fact indexed tables.
Masami Eiri · 2021-12-30 17:20
>>29184
Agree. People get so hung up on the tables starting from 1. Its such a great and easy language to use. Wrote a game in a few hours one day with Lua's Love2D engine. It was my first time using Lua and Love2D and I made a pretty good game in no time. I highly recommend people to try using Lua. Its small and fast. Very easy to use.
dup · 2022-01-02 07:56
>>29184
why should arrays start at zero?
im stupid help
れいん · 2022-01-02 12:13
>>29300
If we need to access an array in batches of size C, then using 0-based indexing, item j of batch i can be found at position C * i + j. Using 1-based indexing, the formula would instead be C * (i - 1) + j.
⍕ · 2022-01-04 23:30
>>29300
so an array can be treated the same way as a pointer
in a[0] 0 is the offset into the array/pointer, NOT the item number.
Nell · 2022-01-05 00:49
>>29184
>>29257
>>29300
>>29307
>>29332
Using C as an argument is retarded. There are other obvious reasons to use 0 (https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html).
Zuse · 2022-01-05 05:54
>>29334
I will give you one very strong, compelling, and logical reason for a zero-based numbering/indexing: mathematics. I really hope you can figure the rest for your self, otherwise, I would suggest giving up on programming.
Batou · 2022-01-05 17:37
>>29336
mathematics is not a reason to do something.
because you could also do pi based indexing or imaginary number indexing.
math has no limits
Davis · 2022-01-05 19:53
>>29336
Fortran has largely been the language used for mathematical computing and it starts at 1
JARGON · 2022-01-05 21:16
>>29336
in math we use 1-indexing pretty much always.
>math has no limits
ISWYDT
quote · 2022-01-10 01:54
>>28104
>Scripting languages are actual garbage
Holy cope how bad do you have to suck at programming to say this soykaf.
over · 2022-01-10 21:17
>>29336
Matlab indexes start at 1
pop · 2022-01-12 13:57
>>29257
All the complaints about 1-indexing are just bikeshedding from people who don't know better. Most of the serious complaints are about the ecosystem, the minimal standard library + poor unicode support, or the unification of hashmaps and arrays with difficult to predict resulting performance characteristics.
Fred Nurk · 2022-01-13 09:18
In addition to being the nicest language to write, it's also pretty much the fastest dynamic language around.
You can keep the whole spec in your head at once, so writing Lua feels 'clean'.
People say that about C, but Lua has no memory or pointer footguns.
Even though there are way less libraries available than more popular languages, it still has pretty much anything you'd need and the available libraries tend to be very nice to use. Love for gamedev and Lapis for webdev are probably nicer than using any other framework in any other language.
It's my favourite language to use, and in an ideal world it'd replace all Python and Javascript (I don't hate Python, Lua's just nicer).
It's not perfect though, I have a couple of gripes:
* Lacks libraries and documentation compared to say Python
* Needs a convention on how to implement classes.
Metatables are beautifully powerful yet simple, and I get that we don't need anything firmer in the language spec, but a recommended convention (something like a PEP) could make things more compatible across different projects.
* Lacks (decent) true multithreading
Lua Lanes comes close but is pretty clunky to use. I wish there were a port of Python's multiprocessing library for Lua.
If anyone knows a good tutorial for using C to implement multithreading in Lua, please let me know.
t · 2022-01-13 09:26
Luakit is the most customisable browser out there, what Awesome does for WMs Luakit does for the web.
Lain Iwakura · 2022-01-13 10:06
>>28606
Arcan looks real interesting but the description and docs are a bit impenetrable.
Do you use it as a daily driver?
Do you have a concise guide to installing/using it?
What are the selling points? What does it allow you to do that regular WMs (if you can call it a WM) don't?
Which of the interfaces do you use? Have you tried the others?
What are the downsides? Presumably there must be some rough edges since it's unfinished software.
Knuth · 2022-01-20 16:02
I'm probably going to end up learning some Lua so that I can configure neovim.
I understand that mpv can also be scripted with Lua so that would be two pieces of software that I regularly use that I can start customizing.
DEBUG-CONTENTS · 2022-01-20 16:35
>>28606
>https://arcan-fe.com/
https://github.com/letoram/arcan
https://arcan-fe.com/2021/11/19/arcan-0-6-1/
That's the most interesting piece of software I've come across this month.
It looks like it's packaged for NixOS too.
Nameless · 2022-01-20 16:50
>>29565
If anyone else is going to try installing this via nix,
you'll also need this:
https://github.com/guibou/nixGL
I found it through this issue:
https://github.com/letoram/arcan/issues/191
With that, I was able to run this:
nixGL arcan welcome It's a bit rough around the edges.
word · 2022-01-22 01:52
I've been browsing around the libraries available for Lua, and its library ecosystem feels very young. A lot of the libraries lack the robustness you'd find in more mature languages.
Chan Siu Ming · 2022-01-22 12:21
>>29586
Lua is in the same camp as languages like Smalltalk and Scheme, where it comes with a small handful of very versatile features and expects you to build everything else atop them. In theory this would make for a very diverse ecosystem, but in practice everyone ends up reimplimenting everything from scratch in a way that's incompatible with everyone else's work.
Yet Another Lainon · 2022-02-07 21:38
>>29592
>>29586
Lua's library ecosystem is C's library ecosystem, for most purposes. Interop is trivial
Jens Hansen · 2022-03-12 02:03
Does anybody remember Lua-tan?
I can't find any pictures of her, not sure how many there were to begin with.
She had a hole in her head just like the lua logo.
Koichiro · 2022-03-14 12:18
>>30388
i only have this one
Chan Siu Ming · 2022-03-19 03:52
>>30406
yea i don't think this is the one i remembered, but im grateful for what i can get
Yuki Nagato · 2022-03-22 06:47
Im curious, has anyone here used lua as an actual os language in some embedded setup?
The closest thing i have done is use it on top of tinycore as only usable userspace application.
Zuse · 2022-03-25 16:23
>>30489
I haven't seen anyone do this but I've been thinking of using it for embedded projects for a long time. Haven't found the occasion yet.
⍕ · 2022-03-25 17:49
How do I define a function inside a table if i want to make an object?
Wirth · 2022-03-25 18:50
>>30559
Not exactly an expert in using Lua with OOP, anyway you define it outside the table like this, same as you would for making a module:
function Object.Function()
...
end now the function "Function" is part of the table "Object" or like this:
function Object:Function()
...
end which will also add a "self" parameter as the first parameter.
In general just remember that Lua uses the prototype pattern instead of classes.
You use objects kind of like this:
-- Plain object
Lain = { Name = "Lain" }
function Lain:WhoAmI()
io.write(self.Name .. "\n")
end
Lain:WhoAmI()
-- Prototyped object
Goddess = { Name = "Nameless" } -- Prototype
function Goddess:New(Object)
Object = Object or { }
setmetatable(Object, self)
self.__index = self
return Object
end
function Goddess:WhoAmI()
io.write(self.Name .. "\n")
end
Haruhi = Goddess:New({ Name = "Haruhi" }) -- Overrides prototype's member
Haruhi:WhoAmI() -- Function WhoAmI is part of the prototype
Nameless = Goddess:New() -- Uses prototype's member
Nameless:WhoAmI() Read chapter 16 of "Programming in Lua".
iron horse · 2022-03-25 20:29
>>30560
Thanks based anon
fsociety · 2022-03-31 17:03
>>30489
I know some dd-wrt parts and extensions are written in lua.
Spike Spiegel · 2022-04-17 21:07
>>26027
It's very simple, and surprisingly more powerful than you'd expect for a simple scripting language (metatables, functions first class citizenship, ...).
I'm sad they removed userdatas, those were nice.
Starting at 1 is fine. If you don't like it, just decrement your algorithms by a little/adjust to have an entry at index 0. If you understand your algorithms then you can adapt them.
Has anyone tried Terra?
https://terralang.org/
It builds upon lua a low-level language which is meta-programmable by lua itself.
The latest release (1.0.0beta3) seems to be a little broken, if you're using the binary. You need to symlink a few libraries to make it work. For instance, if there's a libffi.so.8 file in your /usr/lib/ , do this:
ln -s /usr/lib/libffi.so.8 /usr/libffi.so.6
Same goes for libedit.so.2 and libedit.so.0 .
It's worth the kludge, I think. Seems powerful.
Special Agent Bob · 2022-09-16 11:59
>>26136
He's clearly baiting.
Irvise · 2023-01-03 08:28
Since no one seems to have mentioned it, there is a repository that lists all languages that compile to or are closely related to Lua:
https://github.com/hengestone/lua-languages
And I have the feeling that a lot of people are now realising how small and simple Lua is. I feel like there is more Lua appreciation nowdays, even if its use is dwindling. For example, I did not realise how small the "main" implementation of Lua is:
https://irvise.xyz/Blog/scheme-gnat-bootstrap.html
Also, bumping. I like Lua.
>>30833
There seem to be new releases, your problem may have already been solved
Morpheus · 2023-01-03 19:55
>>33856
Fennel is amazing, I love writing my config scripts in it. +1 for compiling to Lua.
queue · 2023-01-05 22:36
Lua is not Matlab and it is not Mathematica. It was designed to be a scripting language used WITH C. So there's no reason for it to be 1-indexed. Python won, get over it.
Drano · 2023-01-09 18:36
>>33879
How to publicly announce you've never worked in gamedev
xXxscootercooterxXx · 2023-02-15 04:39
Hello lainons. I'm curious as to what anyone's use case for lua is. I think it would be fun to learn for its integration into things such as neovim and nmap,and also as a first programming language. I plan on learning with youtube and "programming in lua: fourth edition",using nvim to write code.Any thoughts about this approach would be appreciated!!!
Ivan Horvat · 2023-02-15 15:08
>>34338
Stop making duplicate threads.
Then read PIL: https://www.lua.org/pil/contents.html
If you want to go fast, there is LuaJIT.
If you want a package manager, there is LuaRocks.
Need a library? Try one of these: https://github.com/LewisJEllis/awesome-lua
>Any thoughts about this approach would be appreciated!!!
Make sure to get a plugin that allows you to quickly send your code to interactive Lua REPL (something similar to Emacs' lua-mode) . Write all example programs by hand and try to modify them (to make them do something slightly different).
sizeof · 2023-03-23 01:10
>>34338
>use case for lua
LUA is a scripting language. You use it to interface logic within a more complicated programming architecture.
Example, Roblox's engine is written in C++, but developers have an easy time maintaining new features, because other assets in Roblox's code are written ontop of the engine, usually in LUA.
Let's say you want to decorate a house.
Building an actual house is actually really fuarrrking complicated and requires a lot of time and work to familiarize yourself with the physical architecture of your house.
However, with LUA, you don't have to actually architecturally change the layout of your house if all you want is to decorate it.
That's what LUA is used for. It easily lets you implement surface features that don't require you to amend your game engine.
If you're planning to use LUA to create your first programs within barebones environment, I recommend switching to Python or even GDScript (exclusively used for the game/ application builder Godot), instead.
They're both much less performant, but the former has soykaf tons of more libraries you can do cool soykaf with, and the latter is part of an easy-to-learn versatile game engine.
cdr · 2023-07-21 18:16
Cool Lua alternative:
https://wren.io/
Knuth · 2023-07-24 05:49
>>29405
It's a reasonable take, Jon Blow and other decent programmerd believe that.
JARGON · 2023-07-24 10:52
>>36551
Jon Blow's biggest talent is his ability to convince people he's an expert on everything he's talking about, which he frequently isn't. Don't get me wrong; he has a lot of very valuable things to say, and his games, especially The Witness, are very good. But he gets a lot of things wrong, and people don't realize it because he speaks an an authoritative way to an audiance that, for the most part, doesn't know any better.
His take on scripting languages is on of those things. Tons of games use high-level scripting languages to implement their high-level logic, and they run just fine.