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

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

Powered by : @r_channels & @reddit2telegram
Download Telegram
Module imports not working with LuaJit

I'm writing a module for a personal project in which I use Penlight, which is installed on a folder inside the project with `luarocks install --tree`, like so:

Project/
| modules/
| bin/
| lib/
| share/
// the usual
| src/
| init.lua
| etc

Inside src/ I have this noscript that requires Penlight, and a simple `local utils = require("pl.utils")` is suficient when running the noscript via `lua noscript.lua`. However when doing the same via luajit I got the following:

/?.lua;/home/linuxbrew/.linuxbrew/share/luajit-2.1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/home/linuxbrew/.linuxbrew/share/lua/5.1/?.lua;/home/linuxbrew/.linuxbrew/share/lua/5.1/?/
init.lua
./?.so;/usr/local/lib/lua/5.1/?.so;/home/linuxbrew/.linuxbrew/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so
luajit: src/dbclass.lua:3: module 'pl.pretty' not found:
no field package.preload['pl.pretty']

I thought "okay, I just need to change path and cpath then" and put:

local version = _VERSION:match("%d+%.%d+")

package.path = f(
"../modules/share/lua/%s/?/?.lua;modules/share/lua/%s/?/init.lua;../modules/share/lua/%s/?.lua;%s", version, version, version, package.path)
package.cpath = f("../modules/lib/lua/%s/?.so;modules/lib/lua/%s/?/?.so;%s", version, version, package.path)

Which worked to recognize the path here Penlight was installed, but now I got an error I'm unfamiliar with and didn't manage to find much help while searching:

luajit: error loading module 'pl.pretty' from file 'modules/share/lua/5.1/pl/init.lua':
modules/share/lua/5.1/pl/init.lua: invalid ELF header

I'll be grateful for any assistance in that regard, I'm yet unfamiliar with ELF libraries, linking and C-related things, so I got a bit lost there.

https://redd.it/1g3q2gj
@r_lua
Has anyone tried to modify lua to allow additional type variants (more than 4 - i.e. 2 bits).... This is my attempt, but Lua becomes unstable.. so I am missing something... anyone know / point me in the right direction ?
https://redd.it/1g44dob
@r_lua
noscript lua for ghub

Hello, I am new to programming. I'm trying to find out how to create a lua noscript to integrate into ghub to define a sequence of actions and mouse movements. Could someone give me a lesson example please? Something like when I click once on g1 the mouse moves to the right by 100 pixels -> right click -> press enter. Thanks for taking your time :D

https://redd.it/1g4bcgi
@r_lua
Nginx json response manipulation

Hi guy
I’ll admit I’m a zero in programming.

I have a problem i tried to solve with ai but I got stuck.


I have a request to a server, and I need to modify the json response before sending it back by adding a field in the json.

It’s driving me insane. Can anyone please help me out?



https://redd.it/1g50rcc
@r_lua
i was running a noscript on logitech ghub and have a new mouse that isnt logitech. is there anyway i can still use the noscript on another software?



https://redd.it/1g5a9nw
@r_lua
Garrys Mod Need Some Help With A Lua Error Im Getting

I seriously need some help with a lua error code im getting with a mod im making, but when i launch the game to go and test my mod it gives me a expected near player lua error everytime i try to test it, Heres the lua error.



[[TFA-VOX\] Sonic The Hedgehog (2010-Present)\] lua/tfa_vox/packs/tfa_vox_sonic_2010_present.lua:83: '}' expected near 'player'

1. TFAVOX_Packs_Initialize - lua/tfa_vox/framework/tfa_vox_packs.lua:120

2. unknown - lua/tfa_vox/framework/tfa_vox_packs.lua:184

3. include - [C\]:-1

4. unknown - lua/autorun/tfa_vox_loader.lua:4


[[TFA-VOX\] Sonic The Hedgehog (2010-Present)\] lua/tfa_vox/packs/tfa_vox_sonic_2010_present.lua:83: '}' expected near 'player'

1. v - lua/tfa_vox/framework/tfa_vox_packs.lua:120

2. unknown - lua/includes/modules/hook.lua:96


[[TFA-VOX\] Sonic The Hedgehog (2010-Present)\] lua/tfa_vox/packs/tfa_vox_sonic_2010_present.lua:83: '}' expected near 'player'

1. TFAVOX_Packs_Initialize - lua/tfa_vox/framework/tfa_vox_packs.lua:123

2. unknown - lua/tfa_vox/framework/tfa_vox_packs.lua:184

3. include - [C\]:-1

4. unknown - lua/autorun/tfa_vox_loader.lua:4


[[TFA-VOX\] Sonic The Hedgehog (2010-Present)\] lua/tfa_vox/packs/tfa_vox_sonic_2010_present.lua:83: '}' expected near 'player'

1. v - lua/tfa_vox/framework/tfa_vox_packs.lua:123

2. unknown - lua/includes/modules/hook.lua:96


[[TFA-VOX\] Sonic The Hedgehog (2010-Present)\] lua/tfa_vox/packs/tfa_vox_sonic_2010_present.lua:83: '}' expected near 'player'

1. TFAVOX_Packs_Initialize - lua/tfa_vox/framework/tfa_vox_packs.lua:120

2. tfa_reload - lua/autorun/lf_playermodel_selector.lua:124

3. func - lua/autorun/lf_playermodel_selector.lua:149

4. unknown - lua/includes/extensions/net.lua:38

https://redd.it/1g5h0mk
@r_lua
New to LUA

So I want to start coding roblox games and know if anyone has a beginner tutorial on how to start they can link.

https://redd.it/1g5jq4t
@r_lua
New to lua

Hi,

I am new to lua and I want to know how to learn it the best.

I am going to use this for roblox game creation.

I know I would need to ask help in the dev reddit for roblox but I also want to learn it just like that.

https://redd.it/1g5ruf3
@r_lua
What is the diff between "hello"[1] and ("hello")[1]?

With the following code, I have two questions.

1. Why does it need a parenthesis around "hello"?
2. Why does it return nil for the second case?

​

$ lua -e 'local a = "hello"1; print(tostring(a))'
lua: (command line):1: unexpected symbol near ''

$ lua -e 'local a = ("hello")[1; print(tostring(a))'
nil

https://redd.it/1g5r2dl
@r_lua
Is there a way to target the current Linux window manager or desktop environment using Lua?

I am trying to write a Lua if statement based on what window manager is currently being used. It's for my wezterm config, so my terminal can work in both gnome and hyprland. Here is an example of what I'm trying to attempt.

if (--[window_manager=hyprland--])
then
config.enablewayland = false
else
config.enable
wayland = true
end

https://redd.it/1g61wdl
@r_lua
How to add a specific value from a table within a table

I'm new to LUA (learning to do it to do stuff in stormworks) and I need to figure out how to add the first value from all values of a table within a table which doesn't have a specified length. I keep trying to look up various YouTube videos and online guides but they're all either lacking this example or they use language completely unfamiliar to me since I don't have a coding background whatsoever.

These are not map coordinates

For example:

Table = {{A1,B1}, {A2,B2}... {AN,BN}}

I want to add all of the A values together.

And separately I want to add all of the B values together. I know how to do it when its just a standard table but my brain breaks trying to figure out how to do it when it's a table within a table.

Thanks for any help in advance!

https://redd.it/1g6uhh1
@r_lua
Code issues (LUA 5.1)

Using an old macro program in WoW. Having issues with this code, and i'm not a coder. It seems to be complaining about the random() and randomseed() commands. Plus it doesn;t like building indicies. I didn't write this, I pared down someone else's free macro code just to get something working to learn from.

I am limited to LUA 5.1 unfortunately. I'm guessing this code is much newer.

Any help would be appreciated. Thanks!

-- Initialize random seed for Lua 5.1
math.randomseed(os.time())

mountListGround = {
"Black War Bear",
"Purple Hawkstrider",
"Black War Wolf",
"Summon Charger",
"Traveler's Tundra Mammoth"
}

mountListFlying = {
"Green Proto-Drake",
"Blue Wind Rider",
"Albino Drake"
}

-- First run after reloading - getting indices
if not builtIndices then

mountListGroundIndices = {}
mountListFlyingIndices = {}
mountListWintergraspIndices = {}

for i = 1, GetNumCompanions("MOUNT") do
local id, name = GetCompanionInfo("MOUNT", i)
if tContains(mountListGround, name) then
tinsert(mountListGroundIndices, i)
if name ~= "Purple Hawkstrider" then
tinsert(mountListWintergraspIndices, i)
end
end
if tContains(mountListFlying, name) then
tinsert(mountListFlyingIndices, i)
end
if name == "Traveler's Tundra Mammoth" then
tundraIndex = i
end
end
builtIndices = true
end

-- Random CallCompanion alias
function callMount(indexTable)
CallCompanion("MOUNT", indexTablemath.random(#indexTable))
end

-- Dismounter
if not IsFlying() and IsMounted() then
Dismount()
end

-- Main function
if not InCombatLockdown() then
cancelShapeshifts()
if IsAltKeyDown() then
CallCompanion("MOUNT", tundraIndex)
else
if not IsFlyableArea() then
callMount(mountListGroundIndices)
else
if not IsFlying() then
if IsShiftKeyDown() then
callMount(mountListGroundIndices)
else
if GetZoneText() == "Wintergrasp" and not GetWintergraspWaitTime() then
callMount(mountListWintergraspIndices)
else
callMount(mountListFlyingIndices)
end
end
end
end
end
end

https://redd.it/1g7l88u
@r_lua
What's the best way to learn Lua?

I'm new to Lua and I'd like to learn it. I have almost no experience with coding except for a bit that I learned from Roblox coding tutorials on Lua. I'd like to learn Lua 5.3, since I heard that Lua 5.4 has some drawbacks that are not good. I'd like to know the best way to learn Lua. I want to learn Lua, to where I can use it professionally and have the deepest understanding of it. I'm thinking after I'm done; I want to build games. I would appreciate any help with this. I'm thinking of learning it from YouTube tutorials like this one: (55) Crash Courses - YouTube, but I'd like to know what would work the best.

https://redd.it/1g7oc7f
@r_lua
my first coding language to learn

Is lua a good starting language to learn and will it help in learning other languages or should i start learning another one

does roblox engine need an expert in lua or just a good knowledge



https://redd.it/1g8uuv6
@r_lua
My new project: LuAssembly

I want to make machine code writing accessible and enjoyable for everyone. My idea is to create a "language" based on Lua's syntax, which will then be converted into an assembly (.asm) file using C++. Afterward, the NASM assembler will turn it into a binary (.bin) file. Does this sound like a good idea?

https://redd.it/1g95yt7
@r_lua
YMT FILES

Hello,

I'm seeking help with modifying .ymt files in Red Dead Redemption 2, specifically for RedM compatibility. Below is a portion of the binary code from a functional .ymt file that works in both story mode and RedM:

PSIN..RP.................".".............c+¡....................ëÁ᛬#.Ú................?€......................?€......ÿÿ................................

I successfully modified the player_three.ymt file, and while it works perfectly in story mode, the character becomes invisible in RedM. I suspect the file is likely becoming corrupted because it's not encrypted as RedM requires. Even OpenIV cannot open the corrupted version, flagging it as a corrupted file.

Any help or insight on how to properly encrypt .ymt files or make them compatible with RedM would be greatly appreciated.

https://redd.it/1g9h7ed
@r_lua
Updates about my project: LuAssembly

I started making the lexer and the parser (On python, because I felt more comfortable to do it with), and I thought and realized that the language wasn't as "Lua-Like" as I initially intended. So I decided to rebrand i'ts name. Unfortunately, because of the subreddit rules, I won't be able to keep updating everyone here. The new name is... .FAST (Fast Assembly Source Translator). I'll post the Github link soon to keep everyone updated.

https://redd.it/1g9xv2t
@r_lua
Is Lua stil used for ML

As a data scientist I knew at the back of my head that one of the most popular Python libraries in ML, PyTorch, started as a Lua package named Torch. It seems that since then the field left Lua completely and turned to Python, a bit of Julia and R, maybe Matlab and C/C++ for embedded stuff.

I came to Lua via Neovim a year ago. Using it, and enjoying it, made me wonder - are there any ML/DS people using Lua these days?

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