Lua - Reddit – Telegram
Lua - Reddit
30 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
Is lua a good choice for making webassembly games instead of rust?

I am trying to make web games in webassembly. have tried rust bit the learning curve for rust is too much . will lua be a good choice to make webassembly games?

https://redd.it/1kdsqlw
@r_lua
how do I make a wait( ) function?

hi, I am new to Lua.

at first, I was using Roblox studio, but I moved to Love2D

in Luau (roblox's alternative for Lua), they have a built in wait()command in their library

Now I realised, I don't have a wait() function in my library

it is pretty self explanatory, I want a wait() function that makes the program wait for a set duration of time before executing the following code

https://redd.it/1kea7gp
@r_lua
I have a question

Where could i learn lua for free? Is there any variants? I want to learn lua but i don't reslly have the money needed for paid guides

https://redd.it/1kgtijl
@r_lua
I'm starting to see Lua everywhere

Not since year ago, I did not think Lua is popular. But today I realize it is everywhere!

https://redd.it/1kgwqul
@r_lua
GitHub · Build and ship software on a single, collaborative platform
https://github.com/bigjimhilljameel

https://redd.it/1kiedkv
@r_lua
Variadic functions

Is there an actual use case for these besides logging functions?

https://redd.it/1kifgi6
@r_lua
Some text stays after clearing, I really tried everything

```Lua
function initialize()
environment = {
day = 0,
states = {day = "day", night = "night"},
state = nil,
radLevel = math.random(0, 10)
}
player = {
health = 100,
maxHealth = 100,
energy = 50,
maxEnergy = 50,
satiety = 100,
maxSatiety = 100
}
statusEffects = {
bleeding = false,
sick = false,
hungry = false,
starving = false
}

energyCosts = {
rest = -25,
supplies = 20,
rad = 10
}

heals = {
nightSleep = 10
}

inventory = {
apple = 0,
cannedSardines = 0,
egg = 0
}

storage = {
apple = 2,
cannedSardines = 1,
egg = 1
}

food = {
apple = {
name = "Apple",
satiety = 10,
energy = 5,
rads = 1,
spoil = true,
foundIn = "Markets"
},
cannedSardines = {
name = "Canned Sardines",
satiety = 20,
energy = 10,
rads = 2,
spoil = false,
foundIn = "Supermarkets"
},
egg = {
name = "Egg",
satiety = 5,
energy = 5,
rads = 4,
spoil = true,
foundIn = "Farms"
},
}

locations = {
home = {
name = "Home",
rads = 1,
danger = 1,
foodSpawn = 0
}
}

playing = true
environment.state = environment.states.night

end

function mainGameLoop()
changeState()
while playing do
clear()
showTime()

if player.satiety <= 20 then
statusEffects.starving = true
print("You are starving!")
elseif player.satiety <= 40 then
statusEffects.hungry = true
print("You are hungry")
end

print("-------------------------")
print("What do you have in mind?")
print("(1) Rest")
print("(2) Look for Supplies")
print("(3) Check Radiation Levels")
print("(4) Check Status")
print("(5) Information")
print("(6) Check Storage")
print("(7) Check Inventory")
listen()
checkResponse()
end
end

function incrementDay()
environment.day = environment.day + 1
environment.radLevel = math.random(0, 10)
end

function changeState()
if environment.state == environment.states.night then
environment.state = environment.states.day
incrementDay()
clear()
print("It's a new day...")
print("Day: "..environment.day)
print("Time: "..environment.state)
print("Done reading? (Press any key)")
io.read()
else
environment.state = environment.states.night
clear()
print("Night falls...")
print("Done reading? (Press any key)")
io.read()
end
player.satiety = player.satiety - 7.5
end

function showInfo()
clear()
print("This is an indie game about surviving! Keep your health up and have fun! Each action takes half a day (Except status check & Information)")
prompt()
end

function listen()
x = io.read()
end

function checkResponse()
if x == "1" then
rest()
changeState()
elseif x == "2" then
if player.energy < energyCosts.supplies then
print("You're too tired...")
print("You should rest. (Press any key)")
io.read()
else
supplies()
changeState()
end
elseif x == "3" then
if player.energy < energyCosts.rad then
print("You're too tired...")
print("You should rest. (Press any key)")
io.read()
else
radLevels()
changeState()
end
elseif x == "4" then
clear()
status()
elseif x == "5" then
showInfo()
elseif x ==
"6" then
storageCheck()
elseif x == "7" then
inventoryCheck()
end
end

function showTime()
print("Day: "..environment.day)
print("Time: "..environment.state)
end

function clear()
-- Don't mind this
os.execute("clear 2>/dev/null || cls 2>/dev/null")
io.write("\27[2J\27[3J\27[H\27[2J\27[3J\27[H") -- Double ANSI clear
io.flush()
end

function status()
io.stdout:setvbuf("no") -- Disable buffering to prevent ghost text
clear()

-- Build the status effects strings first
local effects = {}
if statusEffects.bleeding or statusEffects.sick or statusEffects.hungry or statusEffects.starving then
if statusEffects.bleeding then
table.insert(effects, "You are bleeding! (Bleed)")
end
if statusEffects.sick then
table.insert(effects, "You feel sick... (Sickness)")
end
if statusEffects.hungry then
table.insert(effects, "You are hungry (Hunger)")
end
if statusEffects.starving then
table.insert(effects, "You are starving! (Starvation)")
end
else
table.insert(effects, "None")
end

-- Combine everything into one string
local statusText = table.concat({
"-- Environment Status --\n",
"• Day: ", tostring(environment.day), "\n",
"• Time: ", tostring(environment.state), "\n\n",
"-- Character Status --\n",
"• Health: ", tostring(player.health), "/", tostring(player.maxHealth), "\n",
"• Energy: ", tostring(player.energy), "/", tostring(player.maxEnergy), "\n",
"• Satiety: ", tostring(player.satiety), "/", tostring(player.maxSatiety), "\n\n",
"-- Status Effects --\n",
table.concat(effects, "\n"),
"\n\nDone reading? (Press any key)"
})

io.write(statusText)
io.read()

clear()
io.stdout:setvbuf("line")
end

function radLevels()
local x = math.random(0, 1)
local y = math.random(0, 2)
clear()
estimate = environment.radLevel + x - y

if estimate < 0 then
estimate = 0
end
if environment.radLevel > 0 and environment.radLevel < 3 then
print("Your device reads "..estimate.." rads")
elseif environment.radLevel > 3 and environment.radLevel < 6 then
print("Your device flickers (It reads "..estimate.."rads)")
elseif environment.radLevel > 6 and environment.radLevel < 9 then
print("Your device crackles (It reads "..estimate.."rads)")
else
print("Your device reads 0 rads")
end

print("")
player.energy = player.energy - energyCosts.rad
print("- "..energyCosts.rad.." energy")
prompt()
end

function rest()
clear()
print("You rest...")

player.energy = player.energy - energyCosts.rest
overflowEnergy()

print("You recovered "..math.abs(energyCosts.rest).." energy!")

if environment.state == environment.states.night then
player.health = player.health + 10
overflowHealth()
print("You recovered "..heals.nightSleep.." health!")
end

prompt()
end

function overflowEnergy()
if player.energy > player.maxEnergy then
player.energy = player.maxEnergy
end
end

function overflowHealth()
if player.health > player.maxHealth then
player.health = player.maxHealth
end
end

function prompt()
print("Done reading? (Press any key)")
io.read()
end

function storageCheck()
io.write("\27[2J\27[3J\27[H") -- ANSI clear + scrollback purge
io.flush()

if environment.state == environment.states.night then
io.write("It's too dangerous to access storage at night!\n\nDone reading? (Press any key)")
io.flush()
io.read()
return
end

local displayLines = {
"----- Home Storage Contents -----"
}

local anyStorage = false
for itemKey, quantity in pairs(storage) do
if quantity > 0 and food[itemKey] then
table.insert(displayLines, string.format("- %s: %d", food[itemKey].name,
quantity))
anyStorage = true
end
end
if not anyStorage then
table.insert(displayLines, "(Storage is empty)")
end

table.insert(displayLines, "\n----- Your Inventory -----")
local anyInventory = false
for itemKey, quantity in pairs(inventory) do
if quantity > 0 and food[itemKey] then
table.insert(displayLines, string.format("- %s: %d", food[itemKey].name, quantity))
anyInventory = true
end
end
if not anyInventory then
table.insert(displayLines, "(Inventory is empty)")
end

table.insert(displayLines, "\n----- Transfer Options -----")
table.insert(displayLines, "(1) Move items from Inventory to Storage")
table.insert(displayLines, "(2) Move items from Storage to Inventory")
table.insert(displayLines, "(3) Back")

io.write(table.concat(displayLines, "\n"))
io.flush()

local choice = io.read()

if choice == "1" then
transferItems(true)
elseif choice == "2" then
transferItems(false)
end

io.write("\27[2J\27[3J\27[H")
io.flush()
end

function transferItems(toStorage)
clear()
local source = toStorage and inventory or storage
local destination = toStorage and storage or inventory

local count = 0
local itemsList = {}

for itemKey, quantity in pairs(source) do
if quantity > 0 then
count = count + 1
itemsList[count] = itemKey
print(string.format("(%d) %s: %d", count, food[itemKey].name, quantity))
end
end

if count == 0 then
print(toStorage and "Your inventory is empty!" or "Storage is empty!")
prompt()
return
end

print("\nSelect item (1-"..count..") or (0) Cancel")
local selection = tonumber(io.read()) or 0

if selection > 0 and selection <= count then
local selectedItem = itemsList[selection]
print(string.format("Move how many %s? (1-%d)", food[selectedItem].name, source[selectedItem]))
local amount = tonumber(io.read()) or 0

if amount > 0 and amount <= source[selectedItem] then
source[selectedItem] = source[selectedItem] - amount
destination[selectedItem] = (destination[selectedItem] or 0) + amount
print(string.format("Moved %d %s to %s", amount, food[selectedItem].name, toStorage and "storage" or "inventory"))
else
print("Invalid amount!")
end
end
prompt()
end

function inventoryCheck()
clear()
print("Food | Amount")
for itemKey, quantity in pairs(inventory) do
if food[itemKey] then
print(food[itemKey].name .. ": " .. quantity)
end
end
prompt()
end

initialize()
mainGameLoop()
```

The "Home Storage Contents" seems to stay in the stdout even after clearing... I tried everything I could think of, even asked a friend what was wrong, and he said to print it all as one string, which worked for some, but now it doesn't seem to work. Any ideas guys? It would be much appreciated!

https://redd.it/1kiloa2
@r_lua
I'm looking for a new owner for Lyte2D, my LOVE2D inspired game framework 🙏

Hi everyone,

I actually debutted Lyte2D on this sub, a couple years ago! (https://www.reddit.com/r/lua/comments/111p2rz/lyte2danewgameframeworkthatimmaking/) and (https://www.reddit.com/r/lua/comments/13trs14/lyte2danewgameframeworkv05isoutcoolc/). I haven't posted here since, but Lyte2D has grown.


I'm looking for a new owner/maintainer for Lyte2D. It's a small but powerful game framework for Lua, written in C. It's inspired by LOVE2D but it's even simpler. 1MB or smaller binaries on each platform. Single namespace (everything is under "lyte."), single function to implement ("lyte.tick(...)") instead of update/draw etc. It runs on Windows, Linux, and browsers (WASM) out of the box. MacOS works fine too, but we don't yet have a CI/official build for it yet.

Here're some highlights:

- Simple shapes; lines, circles, rects etc. Transforms...
- Image drawing, including partial rectangles from the image.
- Blend modes (default: alpha blending) and filter modes (default: nearest neighbor for pixel crisp games)
- Audio: looping music and sound effects, pan and pitch control.
- Keyboard/mouse/gamepad input.
- Async fetching application zip for larger game archives
- LOVE2D style app fusing: single executable that's made with merging lyte binary and your game zip. (Works on Windows and Linux, not tested on Mac)
- Single HTML file (that contains an embedded WASM file) for web distribution
- TTF fonts; rendering and font atlas. Crisp performant text rendering (I'm proud with this one)
- Built with Sokol using OpenGL3.3 and GLES3 backends, meaning shaders are shared between ALL targets without code changes. Shader uniform/image params are defined in Lua code. Shaders can be embedded inside Lua files
- It used to have a REPL, Fennel/Teal languages builtin and a half-working physics implementation, but removed these as they were not seeing much use
- Used in jam games, several experiments such as text editors etc.
- Used in one professional Steam game!
- Tiny tiny community, this was not marketed much at all. Couple reddit posts in r/lua and some tweets
- Website: https://lyte2d.com, with guide, samples in wasm and API surface
- Github: https://github.com/lyte2d/lyte2d

The reason I'm looking for a new owner is that I unable to spend the energy this little engine deserves. With the removal of the jankier parts I mentioned above, the remaining API I think is at beta level right now. It would be the new owners path to either keep it with small bug fixes as is, or take it further with more features, different direction etc.

In my opinion, even without a lot of fixes or new features at all, with the right marketing, this little thing can shine.

The correct owner would have some native code experience, he/she would know his way around C/cmake/git/CIs etc even if an expertise is NOT required.

Are you interested? Please DM me here or on twitter or on gmail, tell me what's your general idea of the direction you'd like to take, and your github. If you'd like to join only as a contributor (but not owner) let me know as well.

At "morew4rd" (github, twitter, gmail, reddit -- same handle)

Thank you!

https://redd.it/1kis18u
@r_lua
help! where can i learn the language?

I picked up Python a few weeks ago and now I’ve decided to learn Lua—just out of curiosity. I've searched online but couldn't find many informative videos or articles about learning Lua, aside from its official site, which I personally find a bit hard to follow. Can anyone point me to easier-to-understand resources? Or is Lua just hard to get into at first?

https://redd.it/1kiuoya
@r_lua
How can I compile lua static library for Android?

Hello, I've been trying to compile something valid for my project for days without success...
I basically need the .a lib to use in a VS2019 C++ project...
The project targets Android 19 for ARM and Android 21 for ARM64, it uses Clang 5.0.
VS2019 NDK version is r16b.

While I did got some .a files, with very different sizes when trying, it seems like VS can't find the functions in it, so I guess it's not compiled correctly...
I've tried through WSL (Ubuntu 22.04.2 LTS), but if there's a easier way through Windows, please let me know...

Did anyone have particularly compiled it for Android? I really need to get this working...

https://redd.it/1kiwrlg
@r_lua
Need help uploading accessory to Roblox Studio (Handle error)

Hi everyone,
I’m trying to upload an accessory (a hat) to Roblox Studio, but I keep running into an error:
“Could not find a part called ‘Handle’ inside AccessoryName.”

Here’s what I have:
• A MeshPart (my hat model)
• A Part renamed to “Handle”
• An Attachment inside the Handle

I’ve double-checked everything, but the error still appears when I try to upload.
Does anyone know what might be wrong or what I should check?
I’d really appreciate any help! Thanks in advance!


https://redd.it/1kj2du2
@r_lua
I'm trying to start coding and i need help with luau

I have never coded before ( excluding scratch if that's coding). And I would like to begin coding in roblox studio. but I don't know at all what the commands are ( or whatever its called). can somebody help me by putting a list with all the commands and what they do? I think I can figure out the rest on my own. Thx

https://redd.it/1kk4u67
@r_lua
vscode/vscodium extensions outdated?

Totally new to programming. Are a lot of the lua extensions in vscode outdated? When I go to debug it often throws up errors I don't get in zerobrane studio, especially after user input. Is there a relatively foolproof extension I can install for vscode/vscodium?

https://redd.it/1kkatdm
@r_lua
How long did you take for you to become fluent in Lua?

I'm taking classes for python and only a little fluent in python. After I get fluent in python I will begin with lua because the language is faster. I will still use python.

https://redd.it/1kkltld
@r_lua
expected identifier when parsing expression, got ')'

new to lua and don't know where i am going wrong




game.Players.PlayerRemoving:Connect(function(player)

do

for _, eggy in game.Workspace.poor:GetChildren() do

if not eggy:GetAttribute("Owner") then continue end

\-- the plot is owned by a player

if eggy:GetAttribute('Owner') \~= player.UserId then continue end

\-- we have found the correct plot

eggy:SetAttribute('Taken', nil)

eggy:SetAttribute('Owner', nil)



print('eggy has been destroyed by ' ..player.Name..'!')

break

end

end)

https://redd.it/1kkrtga
@r_lua
Make my project compatible with lua 5.x, or just luajit?

Hello everyone,

I'm currently developing a template language, “Plume”, which translates to Lua.

Originally, I had planned to make it compatible with Lua 5.x, but recently I've been hesitating.

Advantage: it can be used in any Lua environment without any hassle, and use any lib written in lua.

Disadvantage: extra burden of writing and maitienting the code, but in real life it's doable. On the other hand, you run the risk of having Plume libraries that are incompatible with each other, as they are written with different versions of lua... And maybe, for a templating language, having an “official” environment (in this case, luajit) is more interesting than being plug and play.

What do you think? Any other arguments? I'll have to make a choice, but I'm stumped \^\^'.



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