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

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

Powered by : @r_channels & @reddit2telegram
Download Telegram
What and is there a difference between the following?

I am learning lua for love2d, and I am wondering if and if so, what the difference is between writing:

setmetatable(b, a),

a.index = b, and

a = b:new(<params>).

Thank you for your time.

https://redd.it/1lc30tb
@r_lua
Need help rotating one object to look at another object

I have two objects in 3D space, I need a way to find a quaternion to point one objects -Z face towards another.

Each object is represented by a 'Transform' with X, Y and Z information. They also have Vector3 and Quaternion rotation.

The function that I am using to rotate the objects uses Quaternions, so I need it in that format.

I have tried looking elsewhere, but have found nothing that uses Quaternions for this purpose.

For additional context:
This code is part of a modification for the game "Teardown"

There is a function in "Teardown" called "QuatLookAt". this function doesn't work for my purposes since it always expects to be upright

My noscript is a global noscript that pulls transforms from vehicles. this means that the noscripts orientation is different to the orientation of the objects its modifying.

Thus, when the vehicle flips its vertical orientation is the opposite of what the function expects, causing it to break.


Thank you for any help

https://redd.it/1lc9of8
@r_lua
How to make a lua noscript that activates a key when two other keys are pressed?

I've spent like 5 hours trying to do this and I think I'm out of ideas someone please help.


I'm just trying to make a lua noscript for G Hub where if I hold down right click and my side button then my dpi will go down and then return if one of the buttons is released.


I found this noscript and was trying to add a second button into it but I couldn't get it to work:

function OnEvent(event, gkey, family)
if event == "MOUSEBUTTONPRESSED" and gkey == 2 then
PlayMacro("DPI Down")
elseif event == "MOUSEBUTTONRELEASED" and gkey == 2 then
PlayMacro("DPI Up")
end
end

This noscript works but it only works for the one button - I want to press two mouse buttons to activate the DPI change.



https://redd.it/1lco88w
@r_lua
Yet Another Lua5.1 UTF8 library

I was writing a parser and found all the UTF8 support libraries for Lua are not up to my very high standards /hj. Sooo... I made my own. https://gitlab.com/cinntoast/lutf8

It's on the larger side after compilation because it includes the whole utf8proc database inside of it, but that's a trade off. For now it's just for iterating and identifying unicode codepoints, but I plan to add the utf8 regex capabilities in the few coming days.

Features (and plans):
\- Identifying properties of codepoints (implemented)
\- Validating utf8 sequences (implemented)
\- Mapping/Casefolding/Decomposing/etc sequences (implemented)
\- Bitwise options for lua5.3+ (implemented)
\- Meta file included for people using sumneko language server (wip)
\- POSIX Regex Patterns (planned)

Note: It's still largely untested, and a WIP

https://redd.it/1ldy89z
@r_lua
Personal standard - top level expression is =<exp>

How bad of it is me to just use \
= as my universal top level expression trick. No one's going to be using _ as variable.

I come from C. We do this hacky shit 24/7. But I wonder how it is by lua standards lol.

https://redd.it/1ldyx8k
@r_lua
how to use lua-compat-5.3 in C ?

Hello,

What is the proper way to use lua-compat-5.3 from C ?

I did a

luarocks install compat53

but it seems it only installed Lua part (some .so in luarocks' tree), but no compat-5.3.h anywhere ?

thanks

https://redd.it/1ldywz9
@r_lua
I'm writing a custom lua interpreter with modified semantics, I need your feedback

I'm currently making a custom lua interpreter, with a few behavioural changes to the language, and would like to get some feedback before I release the interpreter.

The main differences are with how "nil"-s are handled:

* Setting a field to "nil" doesn't delete it. It simply holds the value of "nil"
* Consequently, an array may contain a "nil" value
* Getting a field that doesn't exist throws an error, instead of returning "nil"
* Coroutines are symmetric, but that doesn't matter much, since there will be assymetric coroutines, using the built-in symmetric ones

Of course, treating "nil" as any other value means that we need a "del" function to delete fields of tables, and since getting a field that doesn't exist is an error, we need a "has" function that checks if a table contains a field.

It goes without saying that this will break quite a lot of existing lua code, but my main argument is that each minor release of lua so far has included a lot of breaking changes.

Aditionally, the built-in compiler will have some extended syntax, but the compiler is completely interchangeable, so a basic lua compiler without all the bells and whistles can be used instead.

Still, the syntax features I have implemented (and plan to implement) so far are the following:

**Procedure literals:**

same as function literals, but are declared as `begin statements... end`, and may be used in a parenthesis-less calls - `my_func begin end`

**While-local and if-local:**

allows the condition of a while or an if to be a declaration. The value of the first declared variable will be used as the condition, the rest will be accessible in the body of the statement

local function split_file(path)
if local basename, ext = path:match "^([^%.]+)%.(.-)$" then
return basename, ext;
else
return path, nil;
end
end

**Methods in table literals:**

Self explanatory imho

local obj = {
a = 1,
b = 2,
function test(self) return self.a + self.b end,
}
print(obj:add());

**Template literals:**

Haven't gotten around to it, but something like JS's template literals:

local world = "Josh";
local str = `Hello, ${world}`;
-- Or alternatively
local str = $"Hello, ${world}";
local str2 = $'Hello, ${world}';
local str3 = $[[
This is quite a long string.
Hello, ${world}
]];

Do the syntactical features look ok, and more importantly, are the behavioral changes I have made worth it or should I keep the original lua specifications (or maybe enable my semantics with a special comment, like `--# use strict`?)

I'm open to critique and ideas.

(Also, don't get the impresssion the compiler requires semicolons, I just prefer writting them...)

https://redd.it/1le9x04
@r_lua
Bitwise operators in LuaJIT

I'm making a Lua interpreter using LuaJIT (for performance), and would like to know if there's any way to implement bitwise operators to LuaJIT. They're in Lua >=5.3 and would like to know if anybody would make a patch for LuaJIT that implemented these. I know about the bit library but I don't really like it. I want true bitwise operators. I also want compound operators and the continue statement, and I found this: https://github.com/SnapperTT/lua-luajit-compound-operators

https://redd.it/1lekabq
@r_lua
how can i learn luau?

well i want to learn luau to make a roblox game. does anyone know a website that is really good for learning luau?

https://redd.it/1lf89xx
@r_lua
Learning Lua from an older version

I'm totally new to Lua or any programming language. I'm trying to learn this language from a YouTube course. Is it ok to learn Lua if the tutor of the course is using an older version and I'm using a more recent one?

https://redd.it/1lffqkb
@r_lua
Can someone help me?

Can someone take the time to help me obfuscate this noscript?

There is the link: https://pastefy.app/MgYbfktM/raw

Thank you if you help me 🙏.

https://redd.it/1lfhj9r
@r_lua
Can someone help me learn lua?

I'm new to coding and have more or less no idea how to noscript. If anyone could help me it would be greatly appreciated

https://redd.it/1lgpqmv
@r_lua
Can someone please help me if they know how the heck I can find this issue with my code for a mod im making for balatro? (the most coding experience i have is Scratch so bear with me lol) Code is below
https://redd.it/1lhlfwy
@r_lua
RN07 Maze-plan-(abandoned)

12:31pm 25/4/25 Just watched 'They cloned Tyrone'. Well I think I want the floor to be a bunch of mazes, like, going down, like an inverted climb, but a different shape of hallway collections each floore, I think that would be a nice way to challenge myself, after all, it wouldn't be too stressful a mission to complete a level each play, would it? It only has to be walls too, not neccessarily ceilinged, and any new ideas can fall to the next level, and then each floor has an entrance and exit, but also it fills the gap, to an extent, doesn't it? So it'll look nice from the outside, and on the inside it's a classic, but it remains then to accept the cliche and grind it from the first, and maybe a few good designs can trickle back up. I got the idea from this carpet pattern the protagonist is dragged by after he's shot in the film I just watched, it's a tesselation of octagonal spaces linked to neighbours, and disjoint encirling ones, bright yellow on black, and it's easy enough, because lets' face it, this multi-level shopping mall stuff is way out of my reach if I'm doing all this philosophizing. I should even do up a plan beforehand, with the floorspace included. But that's next week, or something, because I have had enough of it this week, after spilling my guts and making a show of it to D____. Besides, just a floor each session, that's reasonable, that's the way these things are meant to be played aren't they, I mean, when you clearly aren't Mr. Goodhope saving the damsel and saving the world. Even just a few starter levels would be right, a right job. Sheesh, I am f***ing exhausted.


On the other hand, I've also just downloaded some 'Alien' game and want to check it out and see if it works. Man I'm so goshdarn decadent. I don't know what's more evil, the building or the playing. I mean, what in tarnation are we gonna make that is actually a genuinely good thing, because I can't get away from the meat either when I'm deep in the work, and I don't want to be all taking these offerings against my style of personality development, my social enquiries, my open book ethical standard of discourse, wow there are so many good things I have to say about myself. But then again, the question is what makes you a good person, because it's like, you can do a good thing, or you can have a good thing, but something I haven't tried is this Alien game and to be honest, it's probably the best experience, but am I going to be able to play it the way I want or am I just going to be yo-yo-ing between that and the build and then just decide that it's all meaningless? How do I know the aliens are bad? How do I know I'm going to be sprinting around with loads of cavalry all day with some rad skins in space? But I mean, I don't do skins, do I? I buy skins, but I don't make them. I don't have a skin system, I mean, and I never did, but someone is having to smooth it all out for everyone else, and maybe I know enough about the stones anyway to be able to look at literally anything else, but then obviously there are a few questions I should ask, perhaps in the build I do, like do I really think that it's 'all skins'? Could the universe be 'just skins'? I mean that's like saying it's 'all atoms'. but, yeah, it is, but there's patterns of nature too. It's just, in nature there are levels of patterns all the way down to the atoms, but in games it's no longer a physical level, and the naive approach is punished with existential angst. You think you are a master of alchemy and substance but you still have to beg for the g****, because you ... you can't even wrap up a level, never mind a skin of a cloak and dagger celebrity. But if you want to go down the road of skin acknowledgement there's a rich tapestry of delusion that might make your world for you, all you have to do is be honest and subscribe to that 'theory of skins' and write your damn thesis in the world and see how much discord it causes amongst the locals who have lived in those places for a long time. Like, does anyone really want to get into arguments about
it with you, I mean you're so softly spoken. Go back to your stones.

Edit(23.6.25) It was just a layer of rush. Then RN06 was to produce chardust, and paths through chunks. RN05 will be making it pass for the ages, with some closure.

If anyone would like to help, answer this:
It would be ideal if sketches made with the chalk, or some future chalk, on a block could stay with it when dug to the inventory for later re-placement. So you could just sketch whatever textures you want, and leave them somewhere for later placement as though they were already part of the registered node list.

I also have to include
in chalk/canvas.lua[Ln156-173]: instruction to not apply this draw function when bitmap position is within half the duster's patch width from a surface's edge. It has to check the location of the crosshair for being less than scrubbing distance for the boundary etches, and end the function, so that item does not initiate error sequence. Otherwise I have to bear in mind the repercussions while using the duster in [RSWO][a]
[a]:https://github.com/flowingpoint/RSWO

https://redd.it/1liox5e
@r_lua
Here we go!!! I hope i don't quit like everything i tried in my life. (Any Advice is welcome. I want to finish something)
https://redd.it/1ljtsgh
@r_lua