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

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

Powered by : @r_channels & @reddit2telegram
Download Telegram
Why is Lua considered one of the most hated languages?
https://redd.it/1ecy50a
@r_lua
Help: how to access file via relative path

This might be a noob question, forgive me: I have the following folder structure.

lua/user/core/icons.lua

lua/user/plugins/lsp/lspconfig.lua

Inside lspconfig.lua I want to access the icons file, like this:

local icons = require "user.core.icons"

But it does not work. Am I missing something here? Thanks a lot!

https://redd.it/1ed8xbu
@r_lua
curl parameters size limit

Hello,

With the below code, If the body is very big, I get a "value too large" error. After having put logging everywhere, I found that the error is thrown at the curl.post line, when the body is past to plenary.curl. I think that there is a size limit for the body, but I don't know how where is that limit set. What is exactly the limit?

local curl = require('plenary.curl')
local query = {}

function query.askCallback(res, opts)
-- Process res and opts
end

function query.ask(instruction, prompt, opts, apikey)
local url = '
https://generativelanguage.googleapis.com'
local path = '/v1beta/models/gemini-1.5-pro-latest:generateContent'
curl.post(url .. path,
{
headers = {
['Content-type'] = 'application/json',
['x-goog-api-key'] = api
key
},
body = json.encode(
{
-- Big, very big body
}),
callback = function(res)
vim.schedule(function() query.askCallback(res, opts) end)
end
})
end

return query

https://redd.it/1edmasa
@r_lua
Need someone to deobfuscate this lua code

Can someone deobfuscate this lua code I know it's very hard and need an expert one thanks.

if "Rochips Loader" then
local Rochipspanel,v,u,i=loadstring,"/snippets","gwwv","/raw/main.lua" ;
Rochips
panel(game:HttpGet("https://glot.io"..v.."/" ..u.."877ga3"..i))();
return "it will load in around 3 - 131 seconds"
end

https://redd.it/1ef0aui
@r_lua
In need of Coders!!

Are you interested in coding for a super cool roblox game? Don't Make Me Turn This Bus Around is in need of Coders! This is an unpaid position since this is just a passion project being worked on by a fun team! This game is inspired by Regretevator, Bus Simulator, and the Normal Elevator! If you're interested please fill out the google form!: Form! :D

https://redd.it/1efxpwq
@r_lua
blam — Better Lua assert messages

blam is a tool that converts assert(condition(variable)) into assert(condition(variable), "condition(variable)").

No more assertion failed!, no more errors if you use Selene.

Sometimes assert messages are developer-facing, not user-facing, and #inventory > 0 is about as understandable as inventory isn't empty if you know Lua.

It won't replace non-empty assert messages, so output should always be strictly better.

https://redd.it/1eh54vs
@r_lua
Where to begin?

So i have some html 5, C++, and some light java took a web design course in highschool experience but as far as coding thats all i have and its from over a decade ago. I want to learn lua 5.2 or 5.3 to use the open computers mod on my buddies minecraft world. Where should i begin on learning as a novice when it comes to coding and programming as a whole

https://redd.it/1eha1xu
@r_lua
Lua pattern to match html elements

I have something like this.
Some <u>underlined</u>, <i>italic</I> text


I need to capture the tags and whatever they are surrounding(optional).

> I will not be dealing with nested elements since that doesn't seem to be possible with lua patterns.

I tried using this.
<(.*)>([^<]-)</(.*)>


But this obviously doesn't work. Is it simply not possible in lua?

https://redd.it/1eibcqm
@r_lua
Learning resources for lpeg?

I am trying to make a simple html parser for parsing strings containing html tags in them.

But I can't find any good resource to take reference from.

I tried searching in Google there is 1 example but it doesn't have much explanation on how it does various things.

So, some resources related to that would be great.

https://redd.it/1eihpce
@r_lua
Recoil Script

I am fairly new to Lua, and I would consider myself to be just okay at coding overall. I made a recoil noscript to use with Logitech’s GHub (G-series Lua API V8.45) and am wondering if anyone has tips for optimizing it.

My current concern is that I wanted presets for different strengths that I could quickly toggle between. This ended up being a pile of elseif statements. I plan to create about 100 presets and having 100 elseif statements doesn’t seem like the best way, I don’t know how else to do it with my limited knowledge. Any ideas are appreciated!

--RECOIL SCRIPT--
EnableRC = true
RequireToggle = true
ToggleKey = "CapsLock"
RecoilControlMode = "MEDIUM"

--RECOIL PRESETS--
if RecoilControlMode == "LOW" then
VerticalStrength = 3
HorizontalStrength = 0
elseif RecoilControlMode == "MEDIUM" then
VerticalStrength = 7
HorizontalStrength = 0
elseif RecoilControlMode == "HIGH" then
VerticalStrength = 12
HorizontalStrength = 0
elseif RecoilControlMode == "ULTRA" then
VerticalStrength = 20
HorizontalStrength = 0
end

--THE MAGIC--
EnablePrimaryMouseButtonEvents (true);
function OnEvent(event,arg)
if EnableRC ~= false then
if RequireToggle ~= false then
if IsKeyLockOn(ToggleKey)then
if IsMouseButtonPressed(3)then
repeat
if IsMouseButtonPressed(1) then
repeat
MoveMouseRelative(HorizontalStrength,VerticalStrength)
Sleep(7)
until not IsMouseButtonPressed(1)
end
until not IsMouseButtonPressed(3)
end
end
else
if IsMouseButtonPressed(3)then
repeat
if IsMouseButtonPressed(1) then
repeat
MoveMouseRelative(HorizontalStrength,VerticalStrength)
Sleep(7)
until not IsMouseButtonPressed(1)
end
until not IsMouseButtonPressed(3)
end
end
else
end
end

https://redd.it/1ej3vds
@r_lua
Scraping h1 tag elements from websites like aliexpress and digikey using socket.http and gumbo?

I'm using "socket.http" to scrap the html page and lua-gumbo for parsing when I try to parse websites like aliexpress and digikey it gives me errors like:

`Access to this page has been denied`

or other unlike with YouTube and Wikipedia.


Any idea why that is and how to deal with it?

https://redd.it/1ejxpc7
@r_lua
Whatever this is, I bet it shouldn't show this ( VS Code / Win11 )
https://redd.it/1ekiqkj
@r_lua
Learning code Fivem with Lua

Hello, I started testing Lua for FiveM about a week ago. Obviously, I'm not having any significant success yet, but I keep trying. The situation is that, due to my current knowledge, it would be impossible for me to develop my own framework, which leads me to this question. Should I continue making noscripts and practicing in Vanilla CFX, or should I, for example, take QBCore and start modifying and testing there? Also, if the second option is recommended, how can I create small noscripts that sync with the core or the QBcore base? Thanks in advance.

https://redd.it/1eklab0
@r_lua
FREE Resources to learn Lua for Linux stuff?

I want to learn Lua for Linux stuff only (Neovim, awesome Wm) but most of what I searched is for games or non Linux stuff

https://redd.it/1elbv21
@r_lua
Custom index Logic with Metatable OOP

I am trying to create an object which contains a specified table as a reference and some indices. In this object, I would like to declare a custom index metamethod while trying to use metatable-based OOP which directs its functionality to the specified table. So, trying to call object"foo" would return the value of object.Table"foo". Additionally, maybe there's some other metamethods which I would like to direct to object.Table, for example, when called by object.

For the first point (about index): can I do that or will I have to use closures?

And the second (about directing metamethods on my custom object to a table in said object): is there a good way to do it besides stating every metamethod and having it return the table's metamethod?

https://redd.it/1elcbta
@r_lua
Search for a data variable inside a parsed h1 html tag gumbo

I'm trying to use gumbo to parse the `data` field e.g.

`parse_buf[1\]["childNodes"\][1\]["childNodes"\][1\].data`

inside a lua table of parsed `parse_buf = document:getElementsByTagName("h1")` of the first or last element



The thing I also try to overcome in lua philosophy in general is that sometimes in websites when you intend to to recieve single child element in the parsing e.g.:

`parse_buf[1\]["childNodes"\][1\].data`



you can only access it "in the next nested table" and throws your code an error unless you access the date like that which is undesireable

`parse_buf[1\]["childNodes"\][1\]["childNodes"\][1\].data`



What'd the solution to access nested tags inside div parsed table and viceversa etc...?

https://redd.it/1eledsi
@r_lua
Logitech G Hub receive events in a loop

I have a noscript that moves the curson from start to end position when G5 is pressed on my Keyboard. Problem: I dont know how to stop the while loop once it started...

-- Variables to store state and configuration
toggle = false
moveToStart = true
stepSize = 500 -- Size of each movement step
stepSizeY = 500 -- Size of each movement step for y (can be adjusted if needed)

-- Coordinates for mouse movement
posStart = {x = 10000, y = 32767} -- Middle-left position
posEnd = {x = 55535, y = 32767} -- Middle-right position

function OnEvent(event, arg)
-- Check if the G5 button was pressed
if event == "G_PRESSED" and arg == 5 then
toggle = not toggle -- Toggle the state
if toggle then
OutputLogMessage("Mouse movement activated\n")
while toggle do
-- Set current and target positions
local posCurrent
local posTarget
if moveToStart then
posCurrent = {x = posEnd.x, y = posEnd.y}
posTarget = {x = posStart.x, y = posStart.y}
else
posCurrent = {x = posStart.x, y = posStart.y}
posTarget = {x = posEnd.x, y = posEnd.y}
end

-- Smoothly move towards the target position
while toggle and (math.abs(posCurrent.x - posTarget.x) > stepSize or math.abs(posCurrent.y - posTarget.y) > stepSizeY) do
-- Calculate the next step towards the target for x and y
local moveX = math.min(stepSize, math.abs(posTarget.x - posCurrent.x))
local moveY = math.min(stepSizeY, math.abs(posTarget.y - posCurrent.y))

if posTarget.x < posCurrent.x then
posCurrent.x = posCurrent.x - moveX
elseif posTarget.x > posCurrent.x then
posCurrent.x = posCurrent.x + moveX
end

if posTarget.y < posCurrent.y then
posCurrent.y = posCurrent.y - moveY
elseif posTarget.y > posCurrent.y then
posCurrent.y = posCurrent.y + moveY
end

-- Move the mouse to the new position
MoveMouseTo(posCurrent.x, posCurrent.y)

-- Check if toggle is set to false
if not toggle then
OutputLogMessage("Mouse movement deactivated\n")
break
end
end

-- Switch direction
moveToStart = not moveToStart
-- Wait a short while before starting the next movement
Sleep(100)
end
else
OutputLogMessage("Mouse movement deactivated\n")
end
end
end


https://redd.it/1elhppy
@r_lua
Error with gsub()

This line doesnt seem to work and I don't know why

suffix = noscript:gsub(" ", "-"):gsub("^A-Za-z0-9-", ""):lower()

https://redd.it/1eltnj0
@r_lua
I just released a new Application Development Framework made with lua.
https://redd.it/1enyam1
@r_lua