Lua - Reddit – Telegram
Lua - Reddit
30 subscribers
278 photos
31 videos
4.23K links
News and discussion for the Lua programming language.

Subreddit: https://www.reddit.com/r/lua

Powered by : @r_channels & @reddit2telegram
Download Telegram
I always come back to Lua

After strongly disliking other programming languages.
So, for a brief summary :
\->Python is beautiful to read and write but suffers from poor performance. I know it also has JITs available but they are not very mature and mainstream. Great ecosystem and community but it would help to have a better and eventually officially supported JIT (I know one is in development but it's not a priority).
\->Java hides primitives behind class walls. If you want to send an input word over sockets, you need a Scanner, an InputDataStream, an OutputDataStream, a Socket, a Buffer and whatever else objects do you need. And then keep passing primitives via object implementations and instantiate objects to retrieve primitives. Hurts my head too much...
\->CSharp feels too locked in. Everyone says all you need is the .NET to build anything, truth is there are less libraries to choose from compared to Java. Also it's nicer to write than Java but it's very bloated. Too many things to consider, you can literally get the size of a string in three different ways. Too many ways of doing the same things leads to confusion IMO. Could be fine if I set my own conventions but jumping from codebase to codebase you have to deal with everyone's personal decisions on the code conventions.
\->I didn't use Kotlin much but from what I've seen it doesn't feel like it's own programming language. It feels like a Java with less words. I find it weird when I import packages named "Java" in a Kotlin project. It's not necessarily about practicality but about feeling... feels weird. Feels like repainting your old fence and calling it a totally brand new fence.
\->JavaScript is a language I personally hold responsible for ruining the web first and then ruining app development. If it wasn't for JavaScript I am pretty sure you'd still be able to rock 8GB RAM on a personal computer and still be able to do multitasking to some degree. Right now, 15 tabs of Mozzila consume me 20GB of RAM and most of them are static text (or should be treated as). A few years ago 4GB of RAM was enough to decently run GTA V but whatever.

So, after having to deal with Python's deploymenet and performance problems or getting burned down by Java's verbose and complex boilerplate nature, I always come back at Lua and be like "woah... this small runtime, this syntax any fool can grasp in a few hours and this small footprint". Literally, Lua is the only language I feel comfortable enough writing scalable code in and be sure that whenever I need I can optimize C/C++ backend code.

Sometimes I simply wish Lua was at least in 10 popular general purpose programming languages. Today, CSharp preacher will hate and trash on it even in game development (Microsoft fanatics I guess?). Also, dynamic typing isn't that hated of a features given the fact that var keywaord was introduced in Java and people started to use it like crazy even in production. Even JavaScript devs don't manually static type their variables and TypeScript is not as popular as it was. So, the excuse of static vs dynamic falls of IMO. We have MoonScript or even proper organized code and documented code can do the trick. But Lua is the warm place I always end up going back to whenever I get lost in other programming languages.

https://redd.it/1o9wq20
@r_lua
Zero-setup Lua sandbox for quick noscript testing (runs in your browser)
https://redd.it/1oa41bn
@r_lua
VSCode extension safety

I've added LuaJIT noscripting in a bigger project and it's so exciting, but all Lua plugins on VSCode marketplace are from "unverified" publishers.

Should I worry? It's a proprietary project.

What are other current options with some basic intellisense? (don't need anything fancy and don't want anything heavy)

https://redd.it/1oaiw7g
@r_lua
Need help with Programing a plugin for VLC Media

Hi,
I am new to Lua and I am trying to create a Plugin for VLC Media Player, that shows other media files that are present in the same folder as the media file that is currently being played. However my issue is that the plugin isn't showing any of the other media files that are present. Id appreciate any insight on how I can make this better/ what I am doing wrong

https://preview.redd.it/y3jlpt2zs4wf1.png?width=634&format=png&auto=webp&s=f9fd3eb626c007eb7e0e88a8b80137bd6405c952

https://preview.redd.it/6lkpw8qlt4wf1.png?width=663&format=png&auto=webp&s=2e1b349b75596ffa6243f85a8e31ae5a79b6a2d4



https://redd.it/1ob0wh9
@r_lua
Exploring Lua internals — built a small Lua-like interpreter

Hey everyone,

I’ve been studying how Lua works under the hood lately — the VM, scoping, closures, upvalues, etc.
To really understand it, I decided to reimplement a minimal interpreter in C.
That project turned into something I’m calling LuaX, which started as a learning tool and gradually picked up a few experimental features (like regex and environment chaining).

It’s not 100% compatible with Lua yet, but it runs most of the core language fine, and I’ve been trying to keep it lightweight and transparent so it’s easy to study.
My main goals right now are improving function argument resolutions and continuing to build out the runtime’s modularity.

If you’ve ever tinkered with the Lua VM or made your own interpreter, I’d love to hear how you approached scoping and closures.

Repo (for anyone curious): www.github.com/kenseitehdev/luax.git


https://redd.it/1odszd3
@r_lua
A teensy bit of help please🥲 (return)

Hi! I’ve just started learning lua and I’m quite stuck at this keyword called return

I can’t understand what return does😢

Like why do I need return and wheres it supposed to be used??

(If you have any lua wisdom to share I’d be really happy to hear some please🙇‍♀️)

https://redd.it/1oe4i5a
@r_lua
Lapis on lua.5.4.8

Hola colegas, alguien ha usado lapis en lua5 .4 .8 sobre pacman me está dando error con (failed compiling objetc src/openssl) pero si está instalado o como se arregla, leí en su doc y menciona que si soporta 5.4


https://redd.it/1oe8ue2
@r_lua
Beginner problems having to do with Tables and Functions

Does anybody have beginner problems or know a place that has beginner problems where I am able to use the information of tables and functions?

As these are the features of Lua that I want to know at the current moment.

Please and Thank you

https://redd.it/1oe27mi
@r_lua
Who consumes more memory? Lua 5.4 or LuaJIT 2.1?

Asking it since I found no benchmark

https://redd.it/1oc56hn
@r_lua
Recoil

Anyone have a simple pull down noscript wher i can adjust values, will be used for online game. Thanks

https://redd.it/1ofmewf
@r_lua
What are less common uses for metatables?

The most common is faking inheritance via index. What are some other things it's really useful for?

https://redd.it/1ofsgd0
@r_lua
Pls help

Please help me make world generation in a game about a beach. The beach itself needs to be infinite.

https://redd.it/1ogupa2
@r_lua
I've been itching to code in Lua again, but I've got not project ideas. Anyone have any (reasonable) library requests?

In particular I'd write it in Teal, a typed dialect of Lua, but still I miss the syntax.

https://redd.it/1ohfvt5
@r_lua
For Ru Community

Мне надо выучить Луа, где это можно сделать быстро? Предложите сайты, каналы с обучением пожалуйста

https://redd.it/1ohmzqv
@r_lua
Is There a More Elegant Way of Doing This?

Hi everyone. I need help with a big function I have been working on.  I have a segment of code which is working as intended but due to what it is trying to do it has become a big monstrosity. I've tidied it up as much as I can, but I can't help thinking there must be a better way to do this. 

**A few caveats:**

1. This is a mod for a videogame so I can't really rewrite the codebase for the most fundamental systems.
2. I am very inexperienced, and I only learn what I need to when I need it. That means there is a lot I don't know so please don't just call out a technique by name. Explain what you mean. 

So what is the purpose of the code. This is an injury system, that uses the games existing buff system to keep track of and add injuries to the player when they take certain amounts of damage:

1. Some enemy attacks deal multiple types of damage
2. I only want one damage type to be used to calculate an injury
3. I've created an invisible metre (called a tracker) that tracks that type of injury.
4. For example when the poison "meter" is full the player gets a poison injury
5. I want the game to commit to filling up a meter before starting a new one.
6. Injuries can stack up to a maximum number of stacks

 

The following code is designed to do all that, and I can CONFIRM that it is working as intended in-game. Here are the 4 important segments:

The CHECKS segment tells the game if a player has maximum stacks of an injury. If so then I don't want them receiving a meter for that. This segment creates a shorthand to make later code easier to write.

local bleed_check = has_bleed_injury and #has_bleed_injury >= BuffUtils.get_max_stacks("injury_bleeding")
local health_check = has_max_health_injury and #has_max_health_injury >= BuffUtils.get_max_stacks("injury_max_health")
local poison_check = has_healing_received_illness and #has_healing_received_illness >= BuffUtils.get_max_stacks("illness_poisoned")

This is the randomizer, it takes in multiple damage types and filters them out to 1.

local damage_filter = math.random(1,3)                   
if damage_filter == 1 then
            bleed_damage = false
            poison_damage = false
                                   
elseif damage_filter == 2 then
            bleed_damage = false
            disease_damage = false
                                   
elseif damage_filter == 3 then
            poison_damage = false
            disease_damage = false                     
end

This is the \*\*monstrosity\*\* that actually checks which injuries you have maximum stacks of, and sets those corresponding damage types to false and the remaining damage type to true. This overrides the randomizer.

if bleed_check then bleed_damage = false
            local check_filter = math.random(1,2)
           
            if check_filter == 1 then
                        poison_damage = false
                        disease_damage = true
                       
            elseif check_filter == 2 then
                        disease_damage = false
                        poison_damage = true
            end
 
elseif poison_check then poison_damage = false
            local check_filter = math.random(1,2)
           
            if check_filter == 1 then
                        bleed_damage = false
                        disease_damage = true
                       
            elseif check_filter == 2 then
                        disease_damage = false
                        bleed_damage = true
            end
 
elseif health_check then disease_damage = false
            local check_filter = math.random(1,2)
           
            if check_filter == 1 then
                        bleed_damage = false
                        poison_damage = true
                       
            elseif check_filter == 2 then
                        poison_damage = false
                        bleed_damage = true
            end                                         
end
 
if bleed_check and poison_check then
            disease_damage = true
            bleed_damage = false
            poison_damage = false
 
elseif bleed_check and health_check then
            poison_damage = true
            bleed_damage = false
            disease_damage = false
 
elseif poison_check and health_check then
            bleed_damage = true
            poison_damage = false
            disease_damage = false
end                 
 
if bleed_check and poison_check and health_check then
            bleed_damage = true
            poison_damage = false
            disease_damage = false                                 
end

This segment checks if you have an existing meter (such as poison meter or bleed meter). This overrides everything else, because I want the game to commit to one injury before starting another.

if has_bleed_injury_tracker then
            bleed_damage = true
            poison_damage = false
            disease_damage = false
           
elseif has_healing_received_illness_tracker then
            poison_damage = true
            bleed_damage = false
            disease_damage = false
           
elseif has_max_health_injury_tracker then
            disease_damage = true
            bleed_damage = false
            poison_damage = false
end

I want to fix number 3 since it is an unwieldy monstrosity. Is there a better way of doing this? Some way to trim this code down and make it more elegant?  I am also open to rewriting the whole thing if its necessary.

 I am happy to look up tutorials regarding techniques you guys mention, but please try to explain like you are teaching someone who is brand new and doesn't understand the lingo too well.

https://redd.it/1ohswle
@r_lua