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
Help understanding header of a function

I'm trying to understand what the "&" in this function header means

void ChangeColor(const struct FLinearColor& New_Blade_Color, const struct FLinearColor& New_Blade_Glow_Color);

The FLinearColor struct contains 4 attributes (R, G, B and A), all of which are floats; But whenever I try to use the function by passing a table to the parameters it defaults all of them to 0

Hero[2]:ChangeColor({0.9, 0.9, 0.9, 0.9}, {0.9, 0.9, 0.9, 0.9})
(When I access the variables changed by the function they all print '0.0')

What am I doing/understanding wrong here?

https://redd.it/1gym1gu
@r_lua
Obfuscators

Hello everyone,

I decided to create a Discord bot that works as a Lua obfuscator. This is interesting to me because luaobfuscator.com crashes quite often. The bot uses the free API from luaobfuscator.com to obfuscate files uploaded in the server.

It’s no secret that luaobfuscator.com doesn’t provide very strong obfuscation, just something basic to deter skidders. However, if someone really wants the source code, they can still access it without much effort.

I’m looking for a Python-based obfuscator or websites offering APIs for Lua obfuscation. Any help would be appreciated!

https://redd.it/1h00bii
@r_lua
My 100% free obfuscator

Hello,

I created a free Discord obfuscator bot with no hidden costs. It was a great learning experience for me, so it’s a win-win for everyone.

Enjoy!

https://discord.gg/N25mkPRsk9

https://redd.it/1h008x9
@r_lua
Can someone help add a 5 second cooldown to this barrage noscript?

function onTouched(touch)

local hums = touch.Parent:FindFirstChildOfClass("Humanoid")

if hums then

hums:TakeDamage(0.3)

end

end



function onTouched2(touch2)

local hums2 = touch2.Parent:FindFirstChildOfClass("Humanoid")

if hums2 then

hums2:TakeDamage(0.3)

end

end

noscript.Parent.Activated:Connect(function()

local anim = noscript.Parent.Hurts

local human = noscript.Parent.Parent:FindFirstChildOfClass("Humanoid")

local playanim = human:LoadAnimation(anim)

playanim:Play()

local parts = noscript.Parent.Parent["Left Arm"\].Touched:Connect(onTouched)

local parts2 = noscript.Parent.Parent["Right Arm"\].Touched:Connect(onTouched2)

wait(3)

parts:Disconnect()

parts2:Disconnect()

end)

https://redd.it/1h0bnw4
@r_lua
Need help with a recoil noscript

I downloaded this recoil noscript for Rust. It works fine except for the fact that I need to double click in order for the recoil compensation to kick in. So essentially when I click once it compensates the recoil, but when held down it doesn't work. If I click once and then hold down mouse 1 RIGHT after it, it works.

I need a high IQ individual to help me out here, im not familiar with coding and even tried to ask ChatGPT for help but to no avail. :(

Heres the code:

function hzCf681ZWWcx()
return not IsMouseButtonPressed(1)
end

function IsRightNotPressed()
return not IsMouseButtonPressed(3)
end

function hzCf681ZWWcxfjjs(a)
b = GetRunningTime() + a
repeat
until GetRunningTime() > b - 1
end

function Sleep_extra(gun, a)
local b = GetRunningTime() + a
repeat
if IsMouseButtonPressed(gun) then
break
end
until GetRunningTime() > b - 1
end

function round(x)
return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)
end

function Smoothing(c, d, e)
local f, g, h = 0, 0, 0
local i = d / c
local j = e / c
for k = 0, c do
local l = round(k * i)
local m = round(k * j)
local n = k
MoveMouseRelative(l - f, m - g)
hzCf681ZWWcxfjjs(n - h)
f, g, h = l, m, n
end
end

GunsPatterns = {
[1] = {
[1] =

Thank you!

https://redd.it/1h0v6mo
@r_lua
Any tools to read Lua source, parse the LuaDoc in it, and spit out a data structure of the results?

I'm writing a program that would benefit from being able to read the LuaDoc in a lua source file. I first tried to set up a regex to do this but it would wind up being gigantic and not worth the effort. Are there any such tools out there? I need it to give me a list of the functions and whatever params the user supplied in the LuaDoc.

For example:

---Begin fishing at a spot, allowing the player to click the fishing reticle
---to "complete" the attempt. This function must be called outside a coroutine.
---@param fishList FishableList The list of fish. Preferably, return results of calling Fishing.Find.
---@param junkList JunkableList The list of junk.
---@param reticlePointEntity Entity The point entity where the fishing reticle will spawn.
---@param fishingRod Entity The fishing rod entity, which will be hidden during fishing.
---@param consolationLootTable string Loot table to use as a consolation prize (unsuccessful fishing outcome but there was a fish in the reticle).
---@param catchCallback? function Function to call when catching a fish, with a single entity argument. This will be called in a coroutine.
function Fishing.Setup(fishList, junkList, reticlePointEntity, fishingRod, consolationLootTable, catchCallback)

I need back the function name Fishing.Setup, along with all args and their given types, for all functions in a file.

There seem to be tons of LuaDoc doc makers out there but nothing that kinda specifically stops at just exporting the data in a more programmer-friendly fashion.

https://redd.it/1h0y4wo
@r_lua
How do i decode this Lua code for my TI Nspire CX CAS

Define GreenLagrangeTensor()=

Prgm

Local u1, u2, u3, X1, X2, X3, E11, E22, E33, E12, E13, E23



// Eingabe der Verschiebungsfunktionen

Request "u1(X1,X2,X3):", u1

Request "u2(X1,X2,X3):", u2

Request "u3(X1,X2,X3):", u3



// Berechnung der Komponenten des Green-Lagrange-Verzerrungstensors

E11 := diff(u1, X1) + 0.5 * (diff(u1, X1)\^2 + diff(u2, X1)\^2 + diff(u3, X1)\^2)

E22 := diff(u2, X2) + 0.5 * (diff(u1, X2)\^2 + diff(u2, X2)\^2 + diff(u3, X2)\^2)

E33 := diff(u3, X3) + 0.5 * (diff(u1, X3)\^2 + diff(u2, X3)\^2 + diff(u3, X3)\^2)

E12 := 0.5 * (diff(u1, X2) + diff(u2, X1)) + 0.5 * (diff(u1, X1)*diff(u1, X2) + diff(u2, X1)*diff(u2, X2) + diff(u3, X1)*diff(u3, X2))

E13 := 0.5 * (diff(u1, X3) + diff(u3, X1)) + 0.5 * (diff(u1, X1)*diff(u1, X3) + diff(u2, X1)*diff(u2, X3) + diff(u3, X1)*diff(u3, X3))

E23 := 0.5 * (diff(u2, X3) + diff(u3, X2)) + 0.5 * (diff(u1, X2)*diff(u1, X3) + diff(u2, X2)*diff(u2, X3) + diff(u3, X2)*diff(u3, X3))



// Ausgabe der Ergebnisse

Disp "E11=", E11

Disp "E22=", E22

Disp "E33=", E33

Disp "E12=", E12

Disp "E13=", E13

Disp "E23=", E23

EndPrgm



https://redd.it/1h0ztye
@r_lua
Simple table assignment in for loop not working.

Hey,
I have a decent amount of programming experience, and am trying to learn some lua (for DCS noscripting) But just quickly going through the basic tutorials I ran into a problem. For some reason this simple code, which should just reverse a table won't work:


days = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday",}
revDays = {}

for i,v in ipairs(days) do
revDaysv = i
print('Adding weekday "' .. v .. '" with value: ' .. i)
end

for day,index in ipairs(revDays) do
print(" day " .. day .. " has index " .. index)
end

I know I'm probably missing something obvious, but for the life of me I can't figure it out.
The code itself is copy-pasted from https://lua.org/pil/4.3.5.html

https://redd.it/1h10qd3
@r_lua
Why does Lua have ipairs ?

I am aware of the difference between pairs() and ipairs() but seeing another post here today I was wondering why lua actually has ipairs.

t = { "a", "b", "c", "d"}

for i,v in ipairs(t) do

print(i, v)

end

for i,v in pairs(t) do

print(i, v)

end

does exactly the same thing after all. I always use ipairs for non-dictionary arrays but is it actually worth it? Is there a minimal memory advantage or performance difference?



https://redd.it/1h12gmj
@r_lua
Looking for 5 to 10 people animator and noscripters for developing a game PetQuest DM me for more information and payment



https://redd.it/1h15dnh
@r_lua
Adding of lua plugins support for the C/C++ application

Guys, what would you recommend for developers who want to support Lua plugins in their desktop applications? Any best practices or examples to start?

https://redd.it/1h1x1ch
@r_lua
Redbean + Fengari = fun

I've posted several times on here lately about fengari, but I haven't mentioned Redbean and I don't see a lot of reference to it in the sub.

Anybody else using these two together?

https://redd.it/1h1wivb
@r_lua
lua-language-server cant be called even after adding to path in windows
https://redd.it/1h20r2d
@r_lua
Weird Lua file

Hi! i opened a .lua file and it looked like this :

LuaQ P A@ € E € \€ … ÁÀ œ€ Š܀ AA  E  \ … ÁÁ œ Š܁ B A‚ ‚ E Â \‚ …B Á œ‚ Å C ܂ Ƃà ܂€ à Eà F Ä ZC €B C ˆ AC ƒ Eà F Ä €Ä À €KÃD Á \C€ @ €KCE \C d € € € Š ‡ƒ

i used unluac tool, and i got a more readable version of it.

If i would like to get back to that version ? what should i do ?
can someone tell me if it has been encrypted or it is compiled code?

Thanks a lot in advance

https://redd.it/1h2p9lg
@r_lua
Does anyone have any experience with MapleStory worlds orhave any input about doing this as a project.
https://redd.it/1h2rheo
@r_lua
Is this extension idiomatic Lua? Will it do more harm than good?

C-extension, isstring.c:

#include "precompile.h"

static int isstring (lua_State *L) {
luaL_checkany (L, 1);

/*
int lua_type (lua_State *L, int index);

Returns the type of the value in the given acceptable index, or
LUA_TNONE for a non-valid index (that is, an index to an "empty"
stack position). The types returned by lua_type are coded by the
following constants defined in lua.h: LUA_TNIL, LUA_TNUMBER,
LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION,
LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA. */

lua_pushboolean (L, lua_type (L, 1) == LUA_TSTRING ? 1 : 0);
return 1;
}

int luaopen_isstring (lua_State *L) {
lua_pushcfunction (L, isstring);
return 1;
}

Yes, this can be done in Lua. But to allay efficiency concerns.

usage:

local isstring = require 'isstring'
string.is = isstring

assert (string.is 'adsfasdf')
assert (string.is (9) == false)

for i, v in ipairs {'asdvxc', string, string.is} do
if string.is (v) then print ('is a string:', v)
else print ('not a string:', v) end
end

-- optional metatable.__call
local meta = getmetatable (string)
if not meta then
meta = {}
setmetatable (string, meta)
end
meta.__call = function (self, v) return isstring (v) end

assert (string 'asdfasdf' == true)
assert (string (9) == false)

old = "if type (x) == 'string' then"
new = 'if string (x) then'

print (table.concat ({
'\n-------------------------------------------',
old,
'vs',
new,
string.format (
'\nYou are saved typing %d characters! Wowza!', #old - #new)
}, '\n'))

output:

is a string: asdvxc
not a string: table: 007E0910
not a string: function: 007E31D8

-------------------------------------------
if type (x) == 'string' then
vs
if string (x) then

You are saved typing 10 characters! Wowza!

__call metamethod on the standard string table is not used
currently, might as well give it some use. Already have `tostring` for
string construction

https://redd.it/1h3ueqi
@r_lua
Whats a weird way you do something in lua?

I found that I do oop kind of weirdly and wondered if anyone also did stuff weirdly (granted it has to work).

https://redd.it/1h4874o
@r_lua
What's the conventional technique in Lua for ordered list maintenance?

While tables provide a dictionary (hash), Lua doesn't have, outside of explicit sort, ordered lists. I'm curious what conventional best practice for this problem. Red//Black, AVL, or B trees? Haul in an in-memory DB library such as SQLite and eat the overhead of SQL queries?

What does the wisdom of the crowd say here?

https://redd.it/1h49eoo
@r_lua
Can't Manage to Make HTTP calls for a game mod

First of all, I must say I have no prior modding or Lua background. But, I wanted to create a mod for Baldur's Gate 3 by using BG3 Script Extender, which allows people to write Lua noscripts to interact with the game state.

So, I wanted to see if I could manage to write a Lua noscript that can communicate with SteelSeries Game Engine to manipulate my keyboard's lights, to react to game state (e.g. character health bar on function keys as green light).

With the help of ChatGPT I generated a simple Lua noscript for my use case, which utilizes `socket.http` library:

local http = require("socket.http")

-- Perform the GET request
local response_body, status_code, response_headers = http.request("https://jsonplaceholder.typicode.com/todos/1")

-- Print the response
print("Status Code:", status_code)           -- Similar to `response.status`
print("Response Body:", response_body)       -- Similar to `response.text()`

local function parse_json(json_str)
    local result = {}
    for key, value in json_str:gmatch('"([^"]+)":%s*("?.-["}]?)%s*[,%}]') do
        -- Remove quotes from keys and values if present
        key = key:gsub('"', '')
        if value:match('^".*"$') then
            value = value:sub(2, -2) -- Remove quotes for strings
        elseif value == "true" then
            value = true
        elseif value == "false" then
            value = false
        elseif tonumber(value) then
            value = tonumber(value)
        end
        result[key] = value
    end
    return result
end

-- Parse the JSON response
local data = parse_json(response_body)

-- Access the parsed data
print("Title:", data.noscript)
print("Completed:", data.completed)

The [jsonplaceholder.typicode.com](http://jsonplaceholder.typicode.com) link is only there to test if I can manage to make a call and get a result. I would then replace it with my local Game Engine server URL to communicate with the peripherals.

It seemed to work fine when I ran the Lua noscript using **Lua.exe**. However, after I packaged the noscript and added it as a mod to the game, the Script Extender threw an error:

Loading bootstrap noscript: Mods/SteelSeriesLights/ScriptExtender/Lua/BootstrapServer.lua
bg3se::ExtensionStateBase::LuaLoadGameFile(): Script file could not be opened: Mods/SteelSeriesLights/ScriptExtender/Lua/socket.http
bg3se::lua::State::LoadScript(): Failed to execute noscript: [string "SteelSeriesLights/Server/lights.lua"]:4: attempt to index a nil value (local 'http')
stack traceback:
SteelSeriesLights/Server/lights.lua:4: in main chunk
[C++ Code]: in field 'Include'
builtin://Libs/FileLoader.lua:34: in function <builtin://Libs/FileLoader.lua:6>
(...tail calls...)
SteelSeriesLights/BootstrapServer.lua:1: in main chunk
[C++ Code]: in field 'Include'
builtin://Libs/ModLoader.lua:68: in method 'LoadBootstrap'
builtin://BuiltinLibrary.lua:26: in function <builtin://BuiltinLibrary.lua:25>

From what I can understand, it is interpreting `local http = require("socket.http")` expression as a module file that I created next to my main noscript. To get around this, I checked if I could just put the whole [socket.http code](https://github.com/lunarmodules/luasocket/blob/master/src/http.lua) within the noscript itself, but it also seems to have other dependencies.

Coming from a JavaScript background, I expected to be able to call a method like **fetch** that is built-in to the language, but so far I failed to accomplish my task.

If you could direct me toward any documentation or topic about Lua that might help me understand how to make it work, I would highly appreciate it\^\^

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