Lua - Reddit – Telegram
Lua - Reddit
30 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
How to do both at the same time?

Hi, I'm new to Lua so this might be a very simple question.

I have two different tasks I want to be able to do at the same time. One of them allows one of my macros to start and end by pressing the g5 button, the other moves my mouse left and right repeatedly.

Both of these work individually, but when I put them in the same noscript, only the one I put at the bottom will work. How can I change my code so that both of these can work? Thanks

My code:

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)

if IsKeyLockOn("capslock") then

repeat

MoveMouseRelative(-400,0)

Sleep(70)

MoveMouseRelative(400,0)

Sleep(70)

until not IsKeyLockOn("capslock")

end

end

function OnEvent(event, arg)

if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then

AutoToggle = not AutoToggle

if AutoToggle then

PlayMacro("Candy")

else

AbortMacro()

end

end

end

https://preview.redd.it/audjjcehfn1d1.png?width=682&format=png&auto=webp&s=e260a071ead374bd282f0bbab70791ddebdfe274

https://redd.it/1cwqw0j
@r_lua
Developer Needed

I'm not sure if this is the correct place to put this but I didn't see anything for Lua Jobs anywhere.

I'm looking for a Lua developer for a couple of relatively straight forward projects. Please contact me if interested or let me know if I should post this somewhere else

https://redd.it/1cxku2m
@r_lua
Is roblox actually the best lua game engine/platform?

Ive heard the roblox is the biggest choice when it comes to lua but is that true and if it is, why?


are there any other game engines that use lua and have a interface to work with but are also free to use? If you suggest a engine, have you used it before? Or is roblox the best choice?

https://redd.it/1cxmdea
@r_lua
LuaRT 1.8.0 released

https://preview.redd.it/9e1upzpdg8pb1.png?width=494&format=png&auto=webp&s=49c295d5e8d9dcd3bf974b9afafc14d3fc6d21da

LuaRT is a free and open source Windows programming framework for Lua, with a Windows-optimized runtime library and integrated development tools.

GitHub Repository : [https://github.com/samyeyo/LuaRT](https://github.com/samyeyo/LuaRT)

Homepage : [https://www.luart.org](https://www.luart.org)

*Main features:*

* Desktop/console applications and x86/x64 binaries supported
* The runtime is lightweight and does not rely on any other libraries
* A number of built-in modules are available, including GUI, networking, compression, encryption, etc.
* Object-oriented programming with multilevel inheritance, mixins, constructors, destructors, properties...
* Asynchronous programming with async/await/after paradigm
* Development tools included with rtc, the Lua noscript to executable compiler, LuaRT Studio IDE, the QuickRT REPL, and RTBuilder, a RAD GUI designer

*Since my last post on Reddit, here are the main changes in LuaRT 1.8.0 :*

* Windows dark/light themes support
* Seamless HighDPI and right to left support
* New SQLite, json, and ini modules
* New RAD GUI designer RTBuilder
* And a lot of bugfixes

https://redd.it/1cxvlfd
@r_lua
Ai generated code...

Does this make any sense...

-- A.I.R. Game Engine
local AIR = {}
-- Game Initialization
function AIR:initialize()
self.player = Player:new()
self.level = Level:new()
self.enemies = Enemies:new()
self.ui = UI:new()
end
-- Player Class
Player = {}
function Player:new()
self.class = nil
self.stats = {
health = 100,
strength = 10,
dexterity = 10,
intelligence = 10
}
self.position = {x = 0, y = 0}
self.inventory = {}
end
function Player:levelUp()
self.stats.health = self.stats.health + 10
self.stats.strength = self.stats.strength + 2
self.stats.dexterity = self.stats.dexterity + 2
self.stats.intelligence = self.stats.intelligence + 2
end
function Player:equip(item)
table.insert(self.inventory, item)
end
-- Level Generation
Level = {}
function Level:new()
self.terrain = {}
self.loot = {}
self.enemies = {}
end
function Level:generate()
-- Procedurally generate the level based on biome, difficulty, etc.
for i = 1, 10 do
table.insert(self.terrain, Tile:new())
end
for i = 1, 5 do
table.insert(self.loot, Loot:new())
end
for i = 1, 3 do
table.insert(self.enemies, Enemy:new())
end
end
-- Tile Class
Tile = {}
function Tile:new()
self.type =
grass

self.x = math.random(1, 100)
self.y = math.random(1, 100)
end
-- Loot Class
Loot = {}
function Loot:new()
self.type =

health_potion

self.x = math.random(1, 100)
self.y = math.random(1, 100)
end
-- Enemy Class
Enemy = {}
function Enemy:new()
self.type =

goblin

self.health = 50
self.attack = 10
self.x = math.random(1, 100)
self.y = math.random(1, 100)
end
function Enemy:move(player_position)
-- Move towards the player's position
if self.x < player_position.x then
self.x = self.x + 1
elseif self.x > player_position.x then
self.x = self.x - 1
end
if self.y < player_position.y then
self.y = self.y + 1
elseif self.y > player_position.y then
self.y = self.y - 1
end
end
function Enemy:attack(player)
-- Attack the player
player.health = player.health - self.attack
end
-- UI Class
UI = {}
function UI:new()
self.elements = {}
end
function UI:addElement(element)
table.insert(self.elements, element)
end
function UI:draw()
for _, element in ipairs(self.elements) do
element:draw()
end
end


https://redd.it/1cyi9nu
@r_lua
Luarocks problem.

Hello !
I am trying to install an SQLite wrapper for Lua. I need this functionality for a game made in Love2D.
But I get hit by this error :
"Error: Failed unpacking rock file:..."
I read somewhere that this might be for the reason that Lua libraries are made with Linux in mind and many of those skip the part of providing cross-platform support.
I am tempted to try and use LuaRT, I saw it integrates SQLite functionality, but I am not sure if I can make it work with Love2D (as Love2D uses it's own JIT compiler while LuaRT stands on the 5.4 interpreter).

https://redd.it/1cz2vs3
@r_lua
How to generate definition files automatically using sol2 and LuaLS

I am using sol2 and LuaLS. I want to create LuaLS definition files automatically from all the functions and user types registered through sol2.

Ultimately I want an easier development experience with lua, I do not want to have to constantly look at my c++ function signatures while writing lua noscripts. There are quite a lot of functions so I want to avoid writing the definition files manually.

If it matters, I am using LuaJIT.

If there as a solution that is not specific to sol2 or even LuaLS, I am still interested.

https://redd.it/1czexqu
@r_lua
Help me identify a book

For some reason on mobile I cannot upload a picture but it's a book that says (I will read from top of the cover to bottom) " Lua. Lua programming a beginner's guide 2019 edition. The definitive Lua programming guide" please help me find where I can purchase this book I can find near to none evidence on it online if I use Google lens or something. It knows what book I'm talking about but it just takes me to the Lua Manuel online

https://redd.it/1d01xyx
@r_lua
Love2d: Memory Accumulation with Cyclic State Switching in HUMP?



Hi everyone,I'm working on a project in LÖVE2D using the HUMP library for state management. I have a question about memory management when switching between states that mutually require each other. Suppose I have two state files, state1.lua and state2.lua, and each one requires the other as follows:
-- state1.lua

local state2 = require 'state2'
function state1:enter()
-- Initialization code
end

function state1:update(dt)
-- State switch
Gamestate.switch(require("state2.lua"))
end

-- state2.lua

local state1 = require 'state1'
function state2:enter()
-- Initialization code
end

function state2:update(dt)
-- State switch
Gamestate.switch(require("state1.lua"))
end

My question is: Will the memory of previous state tables accumulate infinitely when switching states using Gamestate.switch? In other words, should I be concerned about potential memory leaks when switching states cyclically in this manner? Thanks in advance.

Edit: Instead of using global variables, I've been encapsulating all necessary values for the current state within the state table itself. I'm not sure if this helps with memory management.

https://redd.it/1d04g04
@r_lua
Goto statement using variables ?, is it possible ?

For a project i am going to use tons of goto statement, however...
returning to the next statement seems impossible.

Is it even possible ???
theoretical example.

print ("begin goto horror")
s_return = "statement1"
goto loop

::statement1::
print ("begin goto horror 1")
s_return = "statement2"
goto loop

::statement2::
print ("begin goto horror 2")
s_return = "statement3
goto loop

::statement3::
print ("begin goto horror 3")
s_return = "statement4"
goto loop

::statement4::
print ("exit goto horror")
goto exit

::loop::
print ("loop line,now we go back")
goto s_return

::exit::
print ("here we the goto mayhem")

in basic language.
when the first statement is called s_return is statement1
so when it jumps to the ::loop:: s_return is statement1
and should jump to "statement1::

and so on,till statement4 what calles the exit and end it.

not the real pro here, but is it even possible ?


https://redd.it/1d08tfr
@r_lua
World of Warcraft Addon/Script question.

https://preview.redd.it/6ao89k5k7o2d1.png?width=355&format=png&auto=webp&s=3af05531d828bc922da97fa0e5812b4ea41314e3

Hello, ever since the new Cataclysm expansion launched my noscript for abbreviating the Player Frame/Target Frame/Focus Frame broke. It still works on the Player Frame only (the left 53k) but as you can see, the Target Frame is not abbreviated (53437) I also get about 30 lua errors.



The noscript I use to abbreviate that used to work is here:

hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function()

PlayerFrameHealthBar.RightText:SetText(AbbreviateNumbers(UnitHealth("player")))

PetFrameHealthBar.RightText:SetText(AbbreviateNumbers(UnitHealth("pet")))

PetFrameManaBar.RightText:SetText(AbbreviateNumbers(UnitPower("pet")))

PlayerFrameManaBar.RightText:SetText(AbbreviateNumbers(UnitPower("player")))

TargetFrameHealthBar.RightText:SetText(AbbreviateNumbers(UnitHealth("target")))

TargetFrameManaBar.RightText:SetText(AbbreviateNumbers(UnitPower("target")))

FocusFrameHealthBar.RightText:SetText(AbbreviateNumbers(UnitHealth("focus")))

FocusFrameManaBar.RightText:SetText(AbbreviateNumbers(UnitPower("focus")))

end)

https://redd.it/1d0q7sz
@r_lua
NEED HELP TRIGGERING ANIMATION

Hello, I am new to noscripting and I am trying to make a humanoid play an animation when walking through a part.

The trigger part.

When walking through this part, the part is supposed to bed destroyed then the Humanoid spawns in playing and triggers another noscript to play the animation and sound. The sound plays and the Humanoid does spawn in for 3 seconds as intended but the animation does not play.

The Trigger noscript that destroys itself when touched and spawns the humanoid in for 3 seconds.

The noscript that is supposed to play the animation once it picks up that the Trigger Part has been destroyed.

Full explorer

So everything works as intended but the Animation does not play (I did insert an AnimationId). Please help with getting the animation to play

https://redd.it/1d0zuw9
@r_lua
lson: JSON+ de/serializer in pure lua

https://github.com/civboot/civlua/tree/main/lib/lson

Hey y'all, I just wrote a JSON+LSON de/serializer in pure Lua. It's public domain and clocks in at only 260 lines of code.

LSON is a new spec I created with slightly cleaner syntax than JSON as well as support for binary data, which I plan to use for the civboot project's "database" etc. It's main advantage is it supports binary data and is slightly cleaner (no commas)

https://redd.it/1d1asy4
@r_lua
Help. I am finding Lua too complicated to work with.

Hello !
First of all, I am by no means a hater. I just want to share the experience I had with this language in the last couple of days. I am primarily a Python developer but I am also working with C++, C# and I've toyed with JavaScript in the past.
My biggest issue with this programming language is the support for errors.
Even in relatively simple applications, when there is something that goes wrong, I am really not shown any information about why my noscript is not working. Upon further investigation, I've found out that there are certain cases where I get returned a "nil" value rather than an exception. This makes it very had to debug the code as I have no clue where to look first, and that forces me to inspect the entire code without the slightest idea of what could cause the problem. At that point I must spam "print" functions to see where the code breaks (and It would seem print won't print me an object's ID if I pass it as a parameter). I don't know if I wrote a wrong variable name or if my function indeed doesn't return or gets any feedback at all. Lua seems very comfortable at throwing nil values even as function parameters, case where my function will simply do nothing rather than give an error. For context, I was working on a sockets application and compared to Python or C#, the process was very tedious.
This reminds me of when I tried to use JavaScript, where my code would do nothing and I wouldn't know why.
I know that Lua was meant to be very lightweight as an embedded language, part of which I understand, based on my limited experience, why it is considered more a noscripting language rather than a GPL.
Another things I dislike are how messy OOP can be in this language (without a proper "class" keyword) or how each statement requires the "end" word for declaration (those "end" words keep stacking and make it harder to read when looking for something specific). But these are things I can live with. But that "nil" thing scares me.
I hope I didn't sound rude in anyway, I simply shared my thoughts and experience (although limited) with this language. I am seeking for feedback and perhaps solutions to my problems.



https://redd.it/1d1e8az
@r_lua
Help with CameraTurnScript (roblox)

I am trying to replicate the way you turn around in Baldi's Basics in Roblox, so I made a code. The thing wrong is, when i hold down the TURN_KEY and I turn around, I'm walking in the direction of when the camera turns around. I need someone to make the movement controls reversed when you hold down the TURN_KEY

https://redd.it/1d1jioz
@r_lua
C++ style oop

Hello,

I made this:

Test = function(isBase, id)
---@private
local o = {
id = id or 5,
base = isBase or true,
}

o.index = o
o.getId = function(self)
return self.id
end

o.isBase = function(self)
return self.
base
end
return o
end

Test2 = function(isBase, id, name)
local o = {
name = name,
}
setmetatable(o, Test(isBase, id))
return o
end

local test = Test2(true, "test")
local test1 = { Test2(false, 15, "lol"), Test2(false, 35, "lol") }

for
, v in ipairs(test1) do
print(v:getId())
end


to somewhat mimic cpp style constructor at least.

So here is my question, is it correct path or it would result with unwanted behaviour?

https://redd.it/1d2z2m6
@r_lua
A template for hybrid development between C and Lua

Symbiotic-Lua is a template for hybrid development between C and Lua, being very useful for hybrid teams, or to facilitate the creation of programs. It generates a native Windows/Linux binary, without the need to install Lua, so it can be used to build desktop apps, or run in environments that cannot install Lua.

https://github.com/OUIsolutions/Symbiotic-Lua

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