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
I want to learn lua

Hello,I want to start learning lua to make games,and idk how I should learn it,i decided on using notepad++ (tell me if there are any better softwares to code in) and idk if I should use this one and learn from youtube videos ,or use roblox and youtube to learn it

https://redd.it/1gndt21
@r_lua
Selene v8.01 released adding 16x02 LCD support
https://redd.it/1gny49a
@r_lua
Making a game using Dcoder...
https://redd.it/1gnyrg7
@r_lua
Lua Pandoc Citation Modifier

I'm trying to create a lua noscript that does the following with pandoc and its internal citeproc:

The current input is: \`(MPD; \[@Somereference2020 noparens\])\`

The desired output is: \`(MPD; Somereference, 2020)\` with the correct internal link to citeproc references.

I'm close, but I can't seem to wrangle removing the preceding space before \`noparens\` on the output.

Current output is: \`(MPD; Somereference, 2020 )\`

Note the space after the year which I've been able to debug to being the preceding space before the \`noparens\` (based on the debug output with carrots).

Thanks in advance to the Lua ninja ... Here's the code

function Cite(cite)
for i, citation in ipairs(cite.citations) do
if citation.suffix and pandoc.utils.stringify(citation.suffix):match("noparens") then
-- Debugging: Print the original suffix
print("Original suffix:", pandoc.utils.stringify(citation.suffix))

-- Remove 'noparens' from the suffix
local new_suffix = pandoc.List{}
for _, item in ipairs(citation.suffix) do
if item.t == "Str" then
-- Remove 'noparens' and trim spaces/commas
item.text = item.text:gsub("noparens", ""):gsub("^%s*,%s*", ""):gsub("%s*,%s*$", "")
if item.text ~= "" then
new_suffix:insert(item)
end
else
new_suffix:insert(item)
end
end
citation.suffix = new_suffix

-- Debugging: Print the modified suffix
print("Modified suffix:", pandoc.utils.stringify(citation.suffix))

-- Debugging: Print the original content
print("Original content:", pandoc.utils.stringify(cite.content))

-- Remove 'noparens' and unnecessary parentheses from the content
local new_content = pandoc.List{}
for _, item in ipairs(cite.content) do
if item.t == "Str" then
-- Remove 'noparens' and parentheses
item.text = item.text:gsub("noparens", ""):gsub("%(", ""):gsub("%)", ""):gsub("^%s*,%s*", ""):gsub("%s*,%s*$", "")
end
if item.text ~= "" then
new_content:insert(item)
end
end
cite.content = new_content

-- Debugging: Print the modified content
print("Modified citation: ^" .. pandoc.utils.stringify(cite) .. "^")

return cite
end
end
end


https://redd.it/1go35uf
@r_lua
(Garry's Mod) Make noscripted entity always grabbable with Gravity Gun

I'm writing a noscripted entity and need it to be always grabbable with the gravity gun. I tried using the GravGunPickupAllowed entity hook for that, but that didn't work. It can be picked up when the gravity gun is supercharged, presumably because it has a higher weight limit, but I need the entity to be able to be picked up by the regular gravity gun without changing the entity's weight. Is there any way I could do such a thing?

https://redd.it/1gogh4m
@r_lua
How to learn

Guys can anyone tell me where you guys know/learn noscripting Lua? I wanna create random stuff

https://redd.it/1gowj2r
@r_lua
How to compile?

Yes, I know there is luac.exe, but thats not what I need.

I have a lua noscript that uses modules I installed from LuaRocks. How can I compile my noscript so that all required modules are compiled with it, so that anyone can run the compiled code, even without anything lua-related installed?

https://redd.it/1gp8sb6
@r_lua
Всем привет,ищу профессионального скриптера на данный момент.

\# Всем привет,ищу профессионального скриптера на данный момент.

**В команде в данный момент-профессиональный vfx artist и профессиональный 3д моделлер/мап билдер**

Идея-как только форситься игра в стиме по типу лонг драйв,или хайп по типу скибиди толчков мы начинаем создавать сырую пародию,к примеру-Fisch,toilet tower defence,a long drive,dusty trip. И постим игру сырой.Как только запостили мы начинаем её рекламить и по тихоньку делать обновы если онлайн растёт,получать мы будем процентами,пример:

2к онлайна 5 минутные сессии(100к робуксов в день)

https://redd.it/1gphju3
@r_lua
What program to use for lua

i found out about lua but idk where to start, i dont know which program to use and where to learn the lua programing language T_T

https://redd.it/1gpi7mb
@r_lua
what is wrong with this code why doesn't it work? i started learning noscripting today and was trying functions

local baseplate = game.Workspace.Baseplate

local function changebaseplate()

baseplate.Material = "pebble"

end

changebaseplate()

https://redd.it/1gpont5
@r_lua
Rainmeter skin not working properly when I try to call a Lua function

The code (look at MeasureInPercent):

Rainmeter
Update=1000
Author=Connect-R
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1
AccurateText=1
MouseScrollUpAction=!SetVariable Scale "(#Scale#+#ScrollMouseIncrement#)"!WriteKeyValue Variables Scale "(#Scale#+#ScrollMouseIncrement#)"!Refresh
MouseScrollDownAction=!SetVariable Scale "(#Scale#-#ScrollMouseIncrement# < 0.2 ? 0.2 : #Scale#-#ScrollMouseIncrement#)"!WriteKeyValue Variables Scale "(#Scale#-#ScrollMouseIncrement# < 0.2 ? 0.2 : #Scale#-#ScrollMouseIncrement#)"!Refresh

Variables
@include=#@#Variables.inc
@include2=#@#Language\#Language#.inc
Scale=0.87

;-------------------------------------------------------------
;-------------------------------------------------------------

MeasureTime
Measure=Time
Format="%#Format#:%M"

MeasureAMPM
Measure=Time
Format="%p"

MeasureTimeOfDay
Measure=Time
Format="%H"
Substitute=#TimeOfDay#

;-------------------------------------------------------------
;-------------------------------------------------------------

MeasureHours
Measure=Time
Format=%H

MeasureMinutes
Measure=Time
Format=%M

MeasureSeconds
Measure=Time
Format=%S

;-------------------------------------------------------------
;-------------------------------------------------------------

AdjustedTimeScript
Measure=Script
ScriptFile=#@#\LuaScript\AdjustedTime.lua

MeasureTotalSeconds
Measure=Calc
Formula=(MeasureHours3600)+(MeasureMinutes60)+(MeasureSeconds)

MeasureInPercent
Measure=String
Formula=&AdjustedTimeScript:CalculatePercentage([&MeasureHours, &MeasureMinutes, &MeasureSeconds)]
DynamicVariables=1

;-------------------------------------------------------------
;-------------------------------------------------------------

Meter24h
Meter=String
MeasureName=MeasureTime
MeasureName2=MeasureTimeOfDay
MeasureName3=MeasureInPercent
StringAlign=Center
FontColor=#Color4#
FontFace=Quicksand Regular
FontSize=(20#Scale#)
X=(600
#Scale#)
Y=(0#Scale#)
Text="Time: %1, %2.#CRLF# Day Progress: %3% ."
AntiAlias=1
NumOfDecimals=0
Percentual=1
Hidden=#Hidden#

[Meter12h]
Meter=String
MeasureName=MeasureTime
MeasureName2=MeasureAMPM
MeasureName3=MeasureTimeOfDay
MeasureName4=MeasureInPercent
StringAlign=Center
FontColor=#Color4#
FontFace=Quicksand Regular
FontSize=(100
#Scale#)
X=(600#Scale#)
Y=(0
#Scale#)
Text="#Time:# %1 %2 #,# %3.#CRLF# Day Progress: %4% ."
AntiAlias=1
NumOfDecimals=0
Percentual=1
Hidden=#Hidden2#

The Lua Script:

function CalculatePercentage(hours, minutes, seconds)    
    if hours >= 4 and hours < 8 then
        return "Time to Sleep."
    elseif hours < 4 then
        hours = hours + 16
    end
    local totalSeconds = (hours 3600) + (minutes 60) + seconds
    abc = (totalSeconds / (86400 - 4 3600)) 100
    return toString(abc)
end

I genuinely have no idea what I am doing wrong. Having an experience programming in Java, C, Python, Lua seems easy, but I really can't call it properly or make it return a value.

What should I do?

https://redd.it/1gqc2uu
@r_lua
LuaLS annotation: class' cannot have multiple values; {Metric,module}

Hello everyone.

I am writing some internal lua modules, I am trying to annotate it correctly (using LLS standard) as there are various classes and modules but I keep having an error of this type :

ldoc --lls -a -d docs/lua/src/
lua/src/prometheus/metric.lua:14: ?: 'class' cannot have multiple values; {Metric,module}

My IDE (Pycharm) is happy with it however and resolves everything without any issue (with annotation based autocompletion)

In this prometheus/ folder, I have my init.lua file that has the following annotation on top

--- @module prometheus
local prometheus = {}

require("prometheus.metric")

...

In the same folder, I have the metric.lua file that contains the following one

--- A Metric
--- @class Metric
--- @field name string the name of the metric
--- @field value number the value of the metric
--- @field labels table the labels of the metric
Metric = {}

...

I don't understand how there conflict as they are on different files ? I found other example of lua project doing this even on the same file and not having any kind of conflicts.

I have no idea what I am doing wrong ?

Thanks

https://redd.it/1grtkb3
@r_lua
How do you run busted multiple times, from Lua?

This is a cross-post from an existing GitHub discussion but I wanted to ask here since the other place seemed unlikely to get a reply.

The summary is that from what I can tell, busted cannot be reasonably called from Lua, let alone more than once. And I'm in a situation where I want to run busted several times and certain things with its results. How can I do it?

I'd like to use busted to profile unittests. But variation can cause tests to perform differently across runs (for example a cold cache vs a warm cache).

What I'd like to do is be able to run busted in a while loop that goes something like this

local maximumtries = 10
local counter = 10
local fastest
time = 2^1023

while true do
local before = os.clock()

runbustedsuite() -- The lua equivalent of this terminal call busted --helper spec/minimal_init.lua --output=my_cool_profiler .

local duration = os.clock() - before

if duration < fastesttime then
counter = maximum
tries
fastesttime = duration
else
counter = counter - 1
end

if counter == 0 then
break
end
end

In the above example, a run that is the fastest of 10 consecutive runs is considered "probably the best time we're going to get". And then I'd use the profile results of that fastest run.

How can I achieve that easily with busted? I checked around it seems like busted isn't like other testing frameworks where you can call the test suite runner directly with lua.

I tried a real example using this:

local function
cleararg()
for key,
in pairs(arg) do
if key ~= 0 then
argkey = nil
end
end
end

local function keeparg(caller)
local original = vim.deepcopy(arg)

caller()

for key, value in pairs(original) do
argkey = value
end
end

local function runbustedsuite(runner)
keeparg(function()
cleararg()

arg[1] = "--ignore-lua"
arg[2] = "--helper=spec/minimal
init.lua"
arg3 = "--output=busted.profileusingflamegraph"

runner({ standalone=false })
end)
end

local function main()
local maximumtries = 10
local counter = 10
local fastest
time = 2^1023

while true do
print("running")
local before = os.clock()

local runner = require("busted.runner")
runbustedsuite(runner)
-- NOTE: It looks like for some reason busted forces `runner()` to
-- return an empty table if it is called more than once. Which is
-- weird. So we have to force-remove the module so we can load it from
-- scratch again.
--
package.loaded["busted.runner"] = nil

local duration = os.clock() - before

if duration < fastest
time then
counter = maximumtries
fastest
time = duration
else
counter = counter - 1
end

if counter == 0 then
break
end
end
end

main()

Because runner takes a combination of arg and options, the interface for this gets hacky. And then there's this if loaded then return function() end else loaded = true end that prevents me from calling the runner more than once. I tried to get around it by forcing the file to reload with package.loaded["busted.runner"] = nil but it isn't working just yet.

I've tried a second pass at this where I basically copy the contents of busted.execute and try to do things that way. And that's difficult in entirely separate ways.

Anyway I'm struggling to
achieve the effect I'm looking for. Any advice would be appreciated. Maybe I'm just looking in the wrong place and there's an easy way to do this?

https://redd.it/1gsifv5
@r_lua
how can i check, if at least 2 of 3 given bools are true?

Hello i have 3 bools (to check, if a coordinate is along the edges of a cube with the given size of 16 units):



local bool_1 = x == 1 or x = 16
local bool_2 = y == 1 or y = 16
local bool_3 = z == 1 or z = 16



how must i setup the if-line to check, if at least 2 of these bool-lines are true?

https://redd.it/1gslmef
@r_lua
How can I just use the term "lua" instead of "lua54"?
https://redd.it/1gt9nmc
@r_lua