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

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

Powered by : @r_channels & @reddit2telegram
Download Telegram
Help me with noscript for GHub.

Hello, im just trying to make noscript that clicks certain points on the screen. Problem is, running noscript doesn't use right mouse button or doesnt use it at all. Also i need to run it, untill certain button is pressed. could you help me with that?

function OnEvent(event, arg)

if event == "PROFILE_ACTIVATED" then

EnablePrimaryMouseButtonEvents(true)

elseif event == "MOUSE_BUTTON_PRESSED" and arg == 3 then

if IsKeyLockOn("capslock") then

repeat

MoveMouseTo(39785,17614)

PressMouseButton(2)

Sleep(10)

ReleaseMouseButton(2)

Sleep(2000)

MoveMouseTo(37258, 17492)

PressMouseButton(2)

Sleep(5)

ReleaseMouseButton(2)

Sleep(1000)

MoveMouseTo(28072, 34741)

PressMouseButton(2)

Sleep(10)

ReleaseMouseButton(2)

Sleep(1000)

MoveMouseTo(28550, 41665)

PressMouseButton(2)

Sleep(10)

ReleaseMouseButton(2)

Sleep(1000)

if not IsMouseButtonPressed(4) then break end

MoveMouseRelative(0,4)

Sleep(10)

PressMouseButton(2)

until not IsMouseButtonPressed(4) -- 4 = "Back"

end

end

end



https://redd.it/1jrjhqp
@r_lua
Luarocks Error: Attempted to index a nil value (field 'LUA_BINDIR')

Whenever I try to do anything with luarocks (ANYTHING) I get a litle pop up with this error:

\[string "src/luarocks/core/cfg.lua"\]:824: attempt to index a nil value (field 'LUA BINDIR')

stack traceback:

\[string "src/luarocks/core/cfg.lua"\]:824: in function 'luarocks.core.cfg.init

\[string "src/luarocks/loader.lua"\]:21: in main chunk \[C\]: in function 'require'

\[string "luarocks"\]:5: in main chunk \[C\]: in ?

I have LuaJIT installed as well as LOVE, which I am trying to get luarocks to work with. I have my paths correctly added, and everything SHOULD work, but it doesn't. I cant do any cmd commands with luarocks because everything returns the same error. I can't find anything online.


(Edit: When I say I was trying to use LOVE with luarocks, I'm not trying to install LOVE, I'm trying to install packages so I can used them WITH love, just FYI.)

https://redd.it/1jrv0tp
@r_lua
Just need some help with keeping letters with ASCII numbers just being singular letters

(This LUA code is specifically for the game Stormworks)
After a few hours, I learned how to decode ASCII letters (ex: 1008403 makes 84 as T and 03 as the 3rd letter), just need some help on saving those letters without them disappearing under a tick since for example 84 rapidly changes into a different number like for example again 65 (which makes A) for a new letter since the name becomes ASCII and only back to single letter(84 becomes 65 without actually adding a new letter because it gets immediately replaced) and 03 rapidly changed as well since it becomes 1st 2nd 3rd letter of the word etc(though the last 2 digits (ex:03 again) helps place one letter to another position like placing to a few pixels to somewhere of a monitor). (apologies if it's confusing since It's a bit hard to explain this).

BTW here's a view of my LUA code to help with it:
function onTick() AR1 =input.getNumber(1) ST1 = string.format("%00d", math.floor(AR1)) V1 = string.char(ST1 % 1000) AR2 =input.getNumber(2) end function onDraw() screen.drawText(32+(AR2*5), 32, V1) end

I'd really appreciate any help since chatGPT gave me a headache without doing anything useful to the code except making it worse.

https://redd.it/1jsbjop
@r_lua
luarocks doesn't work and I don't know why (noobie)

https://preview.redd.it/tpqg39ft23te1.png?width=681&format=png&auto=webp&s=151d13b365db9849f860f4e3c754a634762dac10

welp, installed it with the bat file, added everything to paths, the wiki says to just "luarocks install [rock\]" but uh not quite, what does build type imply?

https://redd.it/1jse28b
@r_lua
Luamacros question: Original input still being sent

I know it's not exactly Lua but the hidmacros forum is dead so this is the only place to ask.

Long story short, I have a gamepad with extra buttons bound to the numpad. I have a Luamacros noscript that catches the input from this controller (believing it to be a keyboard) and outputs F13-F22. However, it still sends the original numpad button too, so it actually reads as numpad1 + F13 and whatnot. I have no idea how to fix this, I've tried running as admin but it won't work. Any idea how to fix this?

https://redd.it/1jso6n4
@r_lua
Hello, LUA members, I need help from you experts to make sure this code will work (I'm a noob at coding)

So, I'm making a noscript to make it so every 10 seconds 300 unanchored parts are added (to lag the game), and after 60 seconds the noscript will stop, will this work?:

game.Workspace:WaitForChild("Treehouse").CanCollide = true --Treehouse is a model.
game.Workspace:WaitForChild("Tree").CanCollide = true --Tree is also a model.


local baseplate = game.Workspace:WaitForChild("Baseplate")

local function createParts()
for i = 1, 300 do

local part = Instance.new("Part")
part.Size = Vector3.new(1, 1, 1) -- Set part size
part.Position = baseplate.Position - Vector3.new(0, 5, 0) + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50, 50)
part.Anchored = false
part.Parent = game.Workspace
end
end

local startTime = tick()
local endTime = startTime + 60

while tick() < endTime do
wait(10)

createParts()
end

Sorry for bothering y'all if I did.

https://redd.it/1jstavq
@r_lua
Announcing Lux - a Modern Package Manager for Lua

It's time Lua got the ecosystem it deserves.



Lux is a new package manager for creating, maintaining and publishing Lua code. It does this through a simple and intuitive CLI inspired by other well-known package managers like cargo.



# Features

Has an actual notion of a "project", with a simple governing `lux.toml` file.
Installs and builds Lua packages in parallel for maximum speed.
Allows you to add/remove/update dependencies with simple commands. This includes finding outdated packages!
Handles the generation of rockspecs for you for every version of your project - say goodbye to 10 rockspec files in your source code.
Has builtin commands for project-wide code formatting (powered by `stylua`) as well as project-wide linting (powered by `luacheck`).
Has native support for running tests with busted.
Uploading a new version of a package is as simple as `lx upload`!
Is fully portable between systems and handles the installations of Lua headers for you, ensuring that all users get the same environment.



# Documentation

The project can be found at https://github.com/nvim-neorocks/lux

A tutorial as well as guides can be found on our documentation website.

We're announcing the project now as it has hit a state of "very usable for everyday tasks". We still have things to flesh out, like error messages and edge cases, but all those fixes are planned for the 1.0 release.

If you have any questions or issues, feel free to reach out in the Github discussions or our issue tracker. Cheers! :)

The Lux Team



https://redd.it/1jt28qr
@r_lua
memory from "luanewuserdata" is not aligned correctly

I am trying to make a binding for CGLM types (such as vec2, vec3, vec4 and matrix types) for a game engine project I am making. I am new to the lua API so I dont know what is causing this.

The memory is not aligned to correctly, so when CGLM tries to do SIMD optimizations it causes seg faults which is a big deal.

anyone know how I can allocate memory in an aligned way for userdatums?

static float *createvec4(lua
State L) {
float
vec = luanewuserdata(L, sizeof(vec4));
luaL
getmetatable(L, "vec4");
luasetmetatable(L, -2);
return vec;
}


static int newvec4(lua
State L) {
float x = luaL_optnumber(L, 1, 0.0f);
float y = luaL_optnumber(L, 2, 0.0f);
float z = luaL_optnumber(L, 3, 0.0f);
float w = luaL_optnumber(L, 4, 0.0f);
float
vec = createvec4(L);


// SEGMENTATION FAULT!
glmvec4copy((vec4){x, y, z, w}, vec);


return 1;
}

https://redd.it/1jt2ihh
@r_lua
Comma separated assignment joy

Just wanted to share something simple that gave me joy.

I've used comma separated assignments before but only in a very limited way. If I have two values I need to return from a function I'll return them as comma separated values so I'll assign them like this:

x,y = somefunction(somevalue)

And that has been the extent of how I have used them.

But yesterday I had a programming problem such that two variables needed to be updated atomically. Something akin to (but more complicated than):

--to be done atomically
x=x+y
y=x-y

Now I obviously can't write it like that as by the time I get to the second line, x is no longer the value it needs to be.

I could write something like...

local oldx=x
x=x+y
y=oldx-y

...but that's really ugly. I could hide the ugly in a function...

x,y = update(x,y)

...but, on a chance I decided to try comma separated expression to see if they were atomic...

x,y = x+y, x-y

...and it worked. The second half of the expression is evaluated without considering the update to the values made by the first half. It works as calculate, calculate, assign, assign. It made me so happy.

Now this may seem like bread and butter coding to some of you. And some of you may look down on me for not knowing all of the nuance of the language I am using (and probably rightly so) but this made me really happy and I thought I'd share in case any of you might enjoy seeing this.

(edit: typos, tidying for clarity, and some auto-uncorrect of code samples)

https://redd.it/1jua53j
@r_lua
Confused about luajit 64 bit integer support

When I google luajit 64 bit integer support the results say that luajit only supports 32 bit integers. However, I discovered luajit has LL and ULL types. Are these not 64 bit integers?

Would anyone be willing to clear up this confusion for me?

Thanks!

https://redd.it/1jv6juh
@r_lua
What's the most correct / safe way to produce Lua code?

I write addons in a restricted version of Lua 5.3 for a game. I have previously had many difficult to track down bugs that come from Lua being a dynamic language, and from me coding in a poor runtime environment.

Expanding on the problem
Just about nothing I get values from or give values to in my runtime environment will warn me or error if unexpected types are present, and adding manual type checking everywhere is clunky.
Sometimes, I will not get error messages when my noscript has crashed.
To reiterate, the game uses Lua 5.3, so I need support for it. I do not have access to some things in the runtime environment, notably metatables, dofile, loadfile, load, and os, coroutine, and io tables.
I do not control the runtime environment I code for unfortunately.

What I want to do
I want to produce Lua code with as many guarantees as possible, as many things locked down as possible. Typed functions, typed variables, static types, more specific types (e.g. enums), immutability, anything I can get. Optimally mostly at compile time, or just without a notable runtime penalty.

My two known contenders:
\- Write regular Lua code, with LuaCATS annotations from LuaLS.
\- Write in Teal, compile to Lua

I'm bummed about every type in Teal being T | nil, and have to be honest and say that it strongly discourages me from wanting to use it, since something could be nil and I would have no warning about it. As an example, the following Teal code has no errors when checking, but crashes immediately upon runtime.

local function add(a: number,b: number): number
return a+b
end
add(nil,nil)

I have heard the type system in LuaLS can at times catch less things than Teal? I've been learning to use both of these, but I'm new to them.
Any thoughts about this? Anything else I should consider trying? I briefly considered making my own Lua version, but stopped when I realized how much work it would be.

https://redd.it/1jvek1t
@r_lua
Logitech Lua noscript does not stop running need help

Hi Guys,

I used ChatGPT to write below noscript for me to randomly select a key to press from a list with G5 being the start button and G4 being the stop button.

This noscript will run as intended but the noscript will not stop when G4 is pressed.

I have to keep clicking G4 for a millions times and sometime it will stop if I am lucy, but most of the time I will have to kill the entire G hub program to stop the program.

Can someone please help, I just need a reliable stop function to the noscript.

GPT is not able to fix the issue after many tries.

-- Define the keys to choose from
local keys = {"1", "2", "4", "5","home", "v", "lshift","u", "i", "p", "k", "f2", "a","8","f5","f9","f10","l"}
local running = false

function OnEvent(event, arg)
if event == "MOUSEBUTTONPRESSED" and arg == 5 then
running = true
OutputLogMessage("Script started. Press G4 to stop.\n")

-- Start the key press loop
while running do
-- Randomly select a key from the keys table
local randomKey = keysmath.random(1, #keys)
-- Simulate the key press
PressAndReleaseKey(randomKey)
OutputLogMessage("Key Pressed: " .. randomKey .. "\n")
Sleep(1000)
PressAndReleaseKey(randomKey)
OutputLogMessage("Key Pressed: " .. randomKey .. "\n")

-- Short sleep to yield control, allowing for responsiveness
Sleep(5000) -- This keeps the loop from consuming too much CPU power

-- Check for the G4 button to stop the noscript
if IsMouseButtonPressed(4) then
running = false
OutputLogMessage("Stopping noscript...\n")
break -- Exit the loop immediately
end
end
elseif event == "MOUSEBUTTONPRESSED" and arg == 4 then
if running then
running = false -- Ensure running is set to false
OutputLogMessage("G4 Pressed: Stopping noscript...\n")
end
end
end

https://redd.it/1jviwe9
@r_lua
`lulu` -- Another Lua Utility Library

# lulu

`lulu` is a small collection of Lua utility modules and classes.

It includes a full-featured `Array` class, an `Enum` class, and a variety of other utility functions and extensions. It also includes a copy of [`scribe`](https://nessan.github.io/scribe), a Lua module for formatted output that gracefully handles Lua tables.

Everyone creates one of these little libraries. This one has a comprehensive long-form [documentation site](https://nessan.github.io/lulu) built using [Quarto](https://quarto.org/).

The code is available [here](https://github.com/nessan/lulu).

# Available Modules

|Module|Purpose|
|:-|:-|
|`lulu.Array`|A full-featured `Array` class for Lua.|
|`lulu.Enum`|An `Enum` class for Lua.|
|`lulu.callable`|Builds "anonymous" functions from strings, etc., a la Penlight.|
|`lulu.messages`|Informational and error messages that are used throughout `lulu`.|
|`lulu.scribe`|Converts Lua objects to strings. Gracefully handles recursive and shared tables.|
|`lulu.table`|Lua `table` extensions that work on *any* table.|
|`lulu.string`|Lua `string` extensions that are added to all string objects.|
|`lulu.xpeg`|An extended `lpeg` module with predefined patterns and useful functions.|
|`lulu.paths`|Some rudimentary path query methods.|
|`lulu.types`|Type-checking methods.|

# Installation

`lulu` has no dependencies. Copy the `lulu` directory and start using it.

Released versions of `lulu` will be uploaded to [LuaRocks](https://luarocks.org), so you should be able to install the library using the following:

luarocks install lulu

# Usage

Assuming your path allows it, you can `require('lulu.lulu')` and have access to all the modules:

require('lulu.lulu')
ENUM 'Suit' {
Clubs = { abbrev = 'C', color = 'black', icon = '', },
Diamonds = { abbrev = 'D', color = 'red', icon = '', },
Hearts = { abbrev = 'H', color = 'red', icon = '', },
Spades = { abbrev = 'S', color = 'black', icon = '', }
}
scribe.putln("%T", Suit)

That will output:

Suit:
[1] Clubs = { abbrev = "C", color = "black", icon = "" },
[2] Diamonds = { abbrev = "D", color = "red", icon = "" },
[3] Hearts = { abbrev = "H", color = "red", icon = "" },
[4] Spades = { abbrev = "S", color = "black", icon = "" }

Alternatively, you can access the modules individually:

local scribe = require('lulu.scribe')
local Array = require('lulu.Array')
local array = Array(1, 2, 3)
array:transform("*", 10)
scribe.putln("array = %t", array)

This will output `array = [ 10, 20, 30 ]`.

# Acknowledgements

This library owes a lot to [Penlight](https://github.com/lunarmodules/Penlight) and the many questions answered over the years on sites like StackOverflow and Reddit.

https://redd.it/1jw0g3a
@r_lua
Killbrick

I wanna code like a custom killbrick for an obby in Roblox but oh my god Copilot is useless.

https://redd.it/1jwc8iu
@r_lua
Anyone know a good starting point?

I know literally nothing about coding, and the "tutorials" ive been searching up usually involve background knowledge i really don't have, anyone know what i should do to start out?

https://redd.it/1jwfya1
@r_lua
Venting - Lua vs C# for game development?

Ok, so I've posted a similar question in the "gamedev" subreddit asking why C# is much more popular than Lua when it comes to making games. A decade ago, whenever someone mentioned "Lua", you sort of instinctively knew they were making games. Lua has been integrated a lot into game engines for noscripting or into games for modding. Lua was also used as a standalone programming language to build games (latest indie hit being Balatro).

As someone who started with Python, Lua's simpliciy, performance and inter-operability with C makes the development experience smooth and satisfying. I prefer it much over C# due to C# being more heavy in features, features I don't always want, need or understand and my experience with Java in the past was bad (the worst being the boilerplate and how every piece of data has it's own class, meaning you need to go through many conversions and getters to get a simple boolean). I get it, C# is "more beautiful" than Java.

But lately C# seems to grow more and more and Lua seems to be forgotten, like, no more recommended or talked as much about. I know big part of it is because of Unity, but what else makes working in C# enjoyable? It can't be all about it being in Unity that even Godot adopted and Defold is attempting to do so too.

So as I said, I posted in the other sub, just to get downvoted big time and be given answers that, while I respect in terms knowledge fidelity, were sort of agressive. "You cant with Lua", "No types = garbage", stuff like that.'So I don't really get it. You could say I am venting now, and that is correct. But i'm more confused than anything.

If I were to respond to the critics brought to Lua, I would say people who use C# don't even use C# at it's full potential as a PL (that being their main reasoning, Lua is a noscripting language while C# is a full-blown PL), they are using it for noscripting in Unity and that comes with a lot of magic abstractions like function decorators which I dislike a lot. So in that scenario, it's like almost not relevant at all if you have type safety or not as long as you're a little disciplined and you have documented your code. Also, GDScript and UE's blueprint system were succesful so far, I don't see why C# is not just a "better" option, but "the must".

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