Resetting system state in between luaunit tests
I have a bunch of automated tests that end up modifying system state. I'm manually unwinding state changes inside my `teardown()` function however it's very bothersome to do this and I have a feeling not all changes are being reset.
My question is: is there a nicer way to reset state during tests? I suppose I could run a separate lua process for every single test but hoping there is a cleaner solution?
Here is the source code: https://github.com/Verubato/framesort/blob/main/tests/Test.lua
https://redd.it/1dvq92x
@r_lua
I have a bunch of automated tests that end up modifying system state. I'm manually unwinding state changes inside my `teardown()` function however it's very bothersome to do this and I have a feeling not all changes are being reset.
My question is: is there a nicer way to reset state during tests? I suppose I could run a separate lua process for every single test but hoping there is a cleaner solution?
Here is the source code: https://github.com/Verubato/framesort/blob/main/tests/Test.lua
https://redd.it/1dvq92x
@r_lua
GitHub
framesort/tests/Test.lua at main · Verubato/framesort
A simple WoW add-on that sorts party, arena, and raid frames. - Verubato/framesort
Phase angle Vs Torque for IPM Motor in FEMM
I have a IPM motor modeled in FEMM and I am trying to get a graph of phase angle Vs torque.
I have been unable to find any sample code for this, does anyone have any suggestions on where to start?
https://redd.it/1dyeonx
@r_lua
I have a IPM motor modeled in FEMM and I am trying to get a graph of phase angle Vs torque.
I have been unable to find any sample code for this, does anyone have any suggestions on where to start?
https://redd.it/1dyeonx
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
how to find libssl.so in lua?
i try http lib in a luarocks project,
but occurred a problem with libssl.so not found
https://redd.it/1dytgdv
@r_lua
i try http lib in a luarocks project,
but occurred a problem with libssl.so not found
❯ bfs -type f -name *libssl* /usr/
bfs: warning: Failed to set locale: No such file or directory
/usr/lib/x86_64-linux-gnu/libssl.so.1.1
/usr/lib/x86_64-linux-gnu/libssl3.so
/usr/lib/x86_64-linux-gnu/libssl.so.3
/usr/lib/x86_64-linux-gnu/libssl.a
/usr/lib/x86_64-linux-gnu/pkgconfig/libssl.pc
❯ lua -l src/setup src/main.lua
lua: error loading module '_cqueues' from file 'lua_modules/lib/lua/5.4/_cqueues.so':
libssl.so.3: cannot open shared object file: No such file or directory
stack traceback:
[C]: in ?
[C]: in function 'require'
lua_modules/share/lua/5.4/cqueues/auxlib.lua:2: in function <lua_modules/share/lua/5.4/cqueues/auxlib.lua:1>
(...tail calls...)
[C]: in function 'require'
lua_modules/share/lua/5.4/http/client.lua:1: in main chunk
[C]: in function 'require'
lua_modules/share/lua/5.4/http/request.lua:5: in main chunk
[C]: in function 'require'
src/main.lua:1: in main chunk
[C]: in ?
https://redd.it/1dytgdv
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
can somepone help me fix this noscript local tool = noscript.Parent
local debounce = false -- To prevent rapid clicking
tool.Activated:Connect(function()
if not debounce then
debounce = true
-- Create a clone of the tool
local clone = tool:Clone()
clone.Pare
https://redd.it/1dyx5xd
@r_lua
local debounce = false -- To prevent rapid clicking
tool.Activated:Connect(function()
if not debounce then
debounce = true
-- Create a clone of the tool
local clone = tool:Clone()
clone.Pare
https://redd.it/1dyx5xd
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Problem generating consistent heightmaps using simplex noise
Example images:
https://preview.redd.it/0rq64777ogbd1.png?width=777&format=png&auto=webp&s=21c7696b6e65289f55ac7227c699880a18133f6d
https://preview.redd.it/1swmq0jcogbd1.png?width=777&format=png&auto=webp&s=d89921594d376ebd5a44ff244321081e4b956e8e
https://preview.redd.it/y5fbmybdogbd1.png?width=777&format=png&auto=webp&s=a3e84ed077815bceada1c78a2897ff295b6c6fc8
I'm trying to generate a 2d terrain from a heightmap created by simplex noise.
The use case is a map that is endlessly traversable in all directions,
so I have copied the source code from this tutorial project [https://www.youtube.com/watch?v=Z6m7tFztEvw&t=48s](https://www.youtube.com/watch?v=Z6m7tFztEvw&t=48s)
and altered it to run in the Solar2d SDK ( don't think my problem is API related )
Currently my project is set up to create 4 chunks, my problem is they have incosistencies. When generating the heightmaps with 1 octave they are consistent, so the problem is caused by having multiple octaves, but I can't figure out why or how to work around it.
I know this is quite an extensive ask, but I'm hoping someone here has experience working with noise and could offer some suggestions. Any pointers are greatly appreciated.
simplex.lua:
[https://github.com/weswigham/simplex/blob/master/lua/src/simplex.lua](https://github.com/weswigham/simplex/blob/master/lua/src/simplex.lua)
tilemap.lua:
local M = {}
local inspect = require("libs.inspect")
local simplex = require("simplex")
local util = require("util")
-- grid
local chunkSize = 50
local width = chunkSize
local height = chunkSize
local seed
local grid
-- vars
local height_max = 20
local height_min = 1
local amplitude_max = height_max / 2
local frequency_max = 0.030
local octaves = 3
local lacunarity = 2.0
local persistence = 0.5
local ini_offset_x
local ini_offset_y
-- aesthetic
local rectSize = 10
local blackDensity = 17
local greyDensity = 10
-- draw chunk from grid
local function draw(iniX, iniY)
for i = 1, height do
for j = 1, width do
local rect = display.newRect(iniX+rectSize*(j-1), iniY+rectSize*(i-1), rectSize, rectSize)
if grid[i][j] > blackDensity then
rect:setFillColor(0)
elseif grid[i][j] > greyDensity and grid[i][j] <= blackDensity then
rect:setFillColor(0.5)
end
end
end
end
-- fill grid with height values
local function fractal_noise(pos_x, pos_y)
math.randomseed(seed)
local offset_x = ini_offset_x+pos_x
local offset_y = ini_offset_x+pos_y
for i = 1, height do
for j = 1, width do
local noise = height_max / 2
local frequency = frequency_max
local amplitude = amplitude_max
for k = 1, octaves do
local sample_x = j * frequency + offset_x
local sample_y = i * frequency + offset_y
noise = noise + simplex.Noise2D(sample_x, sample_y) * amplitude
frequency = frequency * lacunarity
amplitude = amplitude * persistence
end
noise = util.clamp(height_min, height_max, util.round(noise))
grid[i][j] = noise
end
end
end
local function iniSeed()
seed = 10000
ini_offset_x = math.random(-999999, 999999)
ini_offset_y = math.random(-999999, 999999)
end
local function init()
iniSeed()
grid = util.get_table(height, width, 0)
-- dist= frequency_max * 50
local dist = frequency_max * chunkSize
-- generate 4 chunks
fractal_noise(0, 0)
draw(0, 0)
fractal_noise(dist, 0)
draw(rectSize*chunkSize, 0)
fractal_noise(0, dist)
draw(0,
Example images:
https://preview.redd.it/0rq64777ogbd1.png?width=777&format=png&auto=webp&s=21c7696b6e65289f55ac7227c699880a18133f6d
https://preview.redd.it/1swmq0jcogbd1.png?width=777&format=png&auto=webp&s=d89921594d376ebd5a44ff244321081e4b956e8e
https://preview.redd.it/y5fbmybdogbd1.png?width=777&format=png&auto=webp&s=a3e84ed077815bceada1c78a2897ff295b6c6fc8
I'm trying to generate a 2d terrain from a heightmap created by simplex noise.
The use case is a map that is endlessly traversable in all directions,
so I have copied the source code from this tutorial project [https://www.youtube.com/watch?v=Z6m7tFztEvw&t=48s](https://www.youtube.com/watch?v=Z6m7tFztEvw&t=48s)
and altered it to run in the Solar2d SDK ( don't think my problem is API related )
Currently my project is set up to create 4 chunks, my problem is they have incosistencies. When generating the heightmaps with 1 octave they are consistent, so the problem is caused by having multiple octaves, but I can't figure out why or how to work around it.
I know this is quite an extensive ask, but I'm hoping someone here has experience working with noise and could offer some suggestions. Any pointers are greatly appreciated.
simplex.lua:
[https://github.com/weswigham/simplex/blob/master/lua/src/simplex.lua](https://github.com/weswigham/simplex/blob/master/lua/src/simplex.lua)
tilemap.lua:
local M = {}
local inspect = require("libs.inspect")
local simplex = require("simplex")
local util = require("util")
-- grid
local chunkSize = 50
local width = chunkSize
local height = chunkSize
local seed
local grid
-- vars
local height_max = 20
local height_min = 1
local amplitude_max = height_max / 2
local frequency_max = 0.030
local octaves = 3
local lacunarity = 2.0
local persistence = 0.5
local ini_offset_x
local ini_offset_y
-- aesthetic
local rectSize = 10
local blackDensity = 17
local greyDensity = 10
-- draw chunk from grid
local function draw(iniX, iniY)
for i = 1, height do
for j = 1, width do
local rect = display.newRect(iniX+rectSize*(j-1), iniY+rectSize*(i-1), rectSize, rectSize)
if grid[i][j] > blackDensity then
rect:setFillColor(0)
elseif grid[i][j] > greyDensity and grid[i][j] <= blackDensity then
rect:setFillColor(0.5)
end
end
end
end
-- fill grid with height values
local function fractal_noise(pos_x, pos_y)
math.randomseed(seed)
local offset_x = ini_offset_x+pos_x
local offset_y = ini_offset_x+pos_y
for i = 1, height do
for j = 1, width do
local noise = height_max / 2
local frequency = frequency_max
local amplitude = amplitude_max
for k = 1, octaves do
local sample_x = j * frequency + offset_x
local sample_y = i * frequency + offset_y
noise = noise + simplex.Noise2D(sample_x, sample_y) * amplitude
frequency = frequency * lacunarity
amplitude = amplitude * persistence
end
noise = util.clamp(height_min, height_max, util.round(noise))
grid[i][j] = noise
end
end
end
local function iniSeed()
seed = 10000
ini_offset_x = math.random(-999999, 999999)
ini_offset_y = math.random(-999999, 999999)
end
local function init()
iniSeed()
grid = util.get_table(height, width, 0)
-- dist= frequency_max * 50
local dist = frequency_max * chunkSize
-- generate 4 chunks
fractal_noise(0, 0)
draw(0, 0)
fractal_noise(dist, 0)
draw(rectSize*chunkSize, 0)
fractal_noise(0, dist)
draw(0,
rectSize*chunkSize)
fractal_noise(dist, dist)
draw(rectSize*chunkSize, rectSize*chunkSize)
end
init()
return M
util.lua:
local util = {}
function util.get_table(rows, columns, value)
local result = {}
for i = 1, rows do
table.insert(result, {})
for j = 1, columns do
table.insert(result[i], value)
end
end
return result
end
function util.round(value)
local ceil = math.ceil(value)
local floor = math.floor(value)
if math.abs(ceil - value) > math.abs(value - floor) then
return floor
end
return ceil
end
function util.clamp(min, max, value)
if value < min then
return min
end
if value > max then
return max
end
return value
end
function util.is_within_bounds(width, height, x, y)
return 0 < x and x <= width and 0 < y and y <= height
end
util.deque = {}
function util.deque.new()
return { front = 0, back = -1 }
end
function util.deque.is_empty(deque)
return deque.front > deque.back
end
function util.deque.front(deque)
return deque[deque.front]
end
function util.deque.back(deque)
return deque[deque.back]
end
function util.deque.push_front(deque, value)
deque.front = deque.front - 1
deque[deque.front] = value
end
function util.deque.pop_front(deque)
if deque.front <= deque.back then
local result = deque[deque.front]
deque[deque.front] = nil
deque.front = deque.front + 1
return result
end
end
function util.deque.push_back(deque, value)
deque.back = deque.back + 1
deque[deque.back] = value
end
function util.deque.pop_back(deque)
if deque.front <= deque.back then
local result = deque[deque.back]
deque[deque.back] = nil
deque.back = deque.back - 1
return result
end
end
return util
https://redd.it/1dyy3xd
@r_lua
fractal_noise(dist, dist)
draw(rectSize*chunkSize, rectSize*chunkSize)
end
init()
return M
util.lua:
local util = {}
function util.get_table(rows, columns, value)
local result = {}
for i = 1, rows do
table.insert(result, {})
for j = 1, columns do
table.insert(result[i], value)
end
end
return result
end
function util.round(value)
local ceil = math.ceil(value)
local floor = math.floor(value)
if math.abs(ceil - value) > math.abs(value - floor) then
return floor
end
return ceil
end
function util.clamp(min, max, value)
if value < min then
return min
end
if value > max then
return max
end
return value
end
function util.is_within_bounds(width, height, x, y)
return 0 < x and x <= width and 0 < y and y <= height
end
util.deque = {}
function util.deque.new()
return { front = 0, back = -1 }
end
function util.deque.is_empty(deque)
return deque.front > deque.back
end
function util.deque.front(deque)
return deque[deque.front]
end
function util.deque.back(deque)
return deque[deque.back]
end
function util.deque.push_front(deque, value)
deque.front = deque.front - 1
deque[deque.front] = value
end
function util.deque.pop_front(deque)
if deque.front <= deque.back then
local result = deque[deque.front]
deque[deque.front] = nil
deque.front = deque.front + 1
return result
end
end
function util.deque.push_back(deque, value)
deque.back = deque.back + 1
deque[deque.back] = value
end
function util.deque.pop_back(deque)
if deque.front <= deque.back then
local result = deque[deque.back]
deque[deque.back] = nil
deque.back = deque.back - 1
return result
end
end
return util
https://redd.it/1dyy3xd
@r_lua
Reddit
From the lua community on Reddit: Problem generating consistent heightmaps using simplex noise
Explore this post and more from the lua community
Is is possible to test if value is boolean while using only what is thought in chapter 1 of "Programming in Lua, 4th edition"
Exercise 1.6 of the book "Programming in Lua, 4th edition" asks how to check if value is a Boolean without using type. I came out with (value == true or value == false) and it works, but it uses == which has not been introduced so far.
When I learn (or relearn/revise) something in a book and do the exercises, I am very careful to only use what has been covered so far but I don't think that's possible in this case, am I missing something?
https://redd.it/1dz389o
@r_lua
Exercise 1.6 of the book "Programming in Lua, 4th edition" asks how to check if value is a Boolean without using type. I came out with (value == true or value == false) and it works, but it uses == which has not been introduced so far.
When I learn (or relearn/revise) something in a book and do the exercises, I am very careful to only use what has been covered so far but I don't think that's possible in this case, am I missing something?
https://redd.it/1dz389o
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Intercept and count JMS package size
Hi there, how would u guys count the packet size of a JMS TextMessage object.
I am intercepting a JMS message over TCP and I’d like to count the bytes of the message stream. Such that once it hits 10 bytes, I want to fire an if clause to break the loop and only forward the 10 bytes up to JMS.
Any ideas how I could count the bytes?
https://redd.it/1dzwo0f
@r_lua
Hi there, how would u guys count the packet size of a JMS TextMessage object.
I am intercepting a JMS message over TCP and I’d like to count the bytes of the message stream. Such that once it hits 10 bytes, I want to fire an if clause to break the loop and only forward the 10 bytes up to JMS.
Any ideas how I could count the bytes?
https://redd.it/1dzwo0f
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Table size
How do I find the size of lua table in versioin 5.4.x? table.getn, setn and maxn seem to be gone. Is there a way to find the end without counting until nil is found?
Tnx
https://redd.it/1e04ll3
@r_lua
How do I find the size of lua table in versioin 5.4.x? table.getn, setn and maxn seem to be gone. Is there a way to find the end without counting until nil is found?
Tnx
https://redd.it/1e04ll3
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
What is the proper way to run lua in VScode?
I'm just starting, and have already downloaded and installed lua. Currently, I type in the terminal lua54 and then the name of the file I want to run. Is there a way to run code dirctly from the text in the editor without first saving it to a file and running the file?
Any help would be appriciated
https://redd.it/1e05mqg
@r_lua
I'm just starting, and have already downloaded and installed lua. Currently, I type in the terminal lua54 and then the name of the file I want to run. Is there a way to run code dirctly from the text in the editor without first saving it to a file and running the file?
Any help would be appriciated
https://redd.it/1e05mqg
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Can someone help me to decrypt the lua file?
Hello I need to decrypt the lua file. It is made for tibia noscript but its coded and i dont know what is inside. Please help me Download lua file here
https://redd.it/1e0c9h1
@r_lua
Hello I need to decrypt the lua file. It is made for tibia noscript but its coded and i dont know what is inside. Please help me Download lua file here
https://redd.it/1e0c9h1
@r_lua
MediaFire
noscript
MediaFire is a simple to use free service that lets you put all your photos, documents, music, and video in a single place so you can access them anywhere and share them everywhere.
I need help with a bit of code, I'm using G Hub to get a noscript down and I just cannot seem for the life of me, to get this to work.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if (event == "PROFILE_ACTIVATED") then
profile = 1
numberOfProfiles = 8
up = 5
down = 4
end
if (IsKeyLockOn("capslock") == true) then
if (IsMouseButtonPressed(down) and profile > 1) then
profile = profile - 1;
end
if (IsMouseButtonPressed(up) and profile < numberOfProfiles) then
profile = profile + 1;
end
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
I'm not sure how much of it you'll need to see to get a grasp on it here, but I'm trying to get the buttons changed off of my mouse onto 'rshift' and 'rctrl'. I've tried to change it over to IsModifierPressed but I just cant figure it out. Please get back to me if you can help, I've been up trying to solve this on my own for 4 hours and no research is paying off. Thanks.
( P.S. If you need the whole code let me know and ill send the rest. )
https://redd.it/1e1bexu
@r_lua
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if (event == "PROFILE_ACTIVATED") then
profile = 1
numberOfProfiles = 8
up = 5
down = 4
end
if (IsKeyLockOn("capslock") == true) then
if (IsMouseButtonPressed(down) and profile > 1) then
profile = profile - 1;
end
if (IsMouseButtonPressed(up) and profile < numberOfProfiles) then
profile = profile + 1;
end
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
I'm not sure how much of it you'll need to see to get a grasp on it here, but I'm trying to get the buttons changed off of my mouse onto 'rshift' and 'rctrl'. I've tried to change it over to IsModifierPressed but I just cant figure it out. Please get back to me if you can help, I've been up trying to solve this on my own for 4 hours and no research is paying off. Thanks.
( P.S. If you need the whole code let me know and ill send the rest. )
https://redd.it/1e1bexu
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Help
I really want to learn lua for coding in Gmod but I don't really know where to start. Any help?
https://redd.it/1e25eao
@r_lua
I really want to learn lua for coding in Gmod but I don't really know where to start. Any help?
https://redd.it/1e25eao
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
the nothing language server
a small language server I made in 2 and a half hours or so that does nothing
https://gist.github.com/thacuber2a03/7285effd7ad6cec17e24a70fd30be467
https://redd.it/1e3ka4d
@r_lua
a small language server I made in 2 and a half hours or so that does nothing
https://gist.github.com/thacuber2a03/7285effd7ad6cec17e24a70fd30be467
https://redd.it/1e3ka4d
@r_lua
Gist
the nothing language server
the nothing language server. GitHub Gist: instantly share code, notes, and snippets.
I want to learn how to code in lua.
I play a lot of Yu-Gi-Oh especially on EDOpro. That program allows you to make custom cards. The code for the cards is done in lua. I have no background in coding at all. I want to try to learn it so I can make my own cards. What is the best way for me to learn about coding in lua. Is lua a good start or should I learn a different programming language first?
https://redd.it/1e3oqwa
@r_lua
I play a lot of Yu-Gi-Oh especially on EDOpro. That program allows you to make custom cards. The code for the cards is done in lua. I have no background in coding at all. I want to try to learn it so I can make my own cards. What is the best way for me to learn about coding in lua. Is lua a good start or should I learn a different programming language first?
https://redd.it/1e3oqwa
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I get there's a lot of these but I need help to get an IDE for lua
ok so I used to code in python but I didn't really like it, in python I was using sublime text, so now I'm switching to Lua, but I'm basically still a newbie to coding, the reason why I'm switching to Lua specifically is just to mod tboi. I've looked online for information on how to code and I'll look more in depth about that later, but for now I need an IDE to program in lua so could anyone help me?
https://redd.it/1e3tuzv
@r_lua
ok so I used to code in python but I didn't really like it, in python I was using sublime text, so now I'm switching to Lua, but I'm basically still a newbie to coding, the reason why I'm switching to Lua specifically is just to mod tboi. I've looked online for information on how to code and I'll look more in depth about that later, but for now I need an IDE to program in lua so could anyone help me?
https://redd.it/1e3tuzv
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Decryption / FXAP
Hi! I have obtained a FiveM Script which I need urgently to work but I'm scared to try it because it might be malicious. The problem: I can't check the code because it is encrypted. Pretty sure it has something to do with with FXAP because it says on the top as the only readdable code and there is also a .fxap file. Any idea/help? Rest of the files arent encrypted and look good. Thanks in advance.
my code :\/
https://redd.it/1e46wlz
@r_lua
Hi! I have obtained a FiveM Script which I need urgently to work but I'm scared to try it because it might be malicious. The problem: I can't check the code because it is encrypted. Pretty sure it has something to do with with FXAP because it says on the top as the only readdable code and there is also a .fxap file. Any idea/help? Rest of the files arent encrypted and look good. Thanks in advance.
my code :\/
https://redd.it/1e46wlz
@r_lua
newproxy and userdata
I have been using Lua for many years now as it is my goto language.
However, I have never understood the purpose of userdatas.
From what I know, it sort of works like a table, where you can set a metatable to it and extend its functionality.
So what is the purpose of userdatas in Lua?
https://redd.it/1e4jejy
@r_lua
I have been using Lua for many years now as it is my goto language.
However, I have never understood the purpose of userdatas.
From what I know, it sort of works like a table, where you can set a metatable to it and extend its functionality.
So what is the purpose of userdatas in Lua?
https://redd.it/1e4jejy
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Question regarding Lua.
So I'm 16 now and planning on studying CS. So I thought I should start learning a language to help me later on at University. But me and my friend were talking about Making a Roblox game. Roblox uses the language Lua. The problem is I wanted to learn a coding language that would help me in the future. And I just wanted to know if me learning Lua would help me with other coding languages, or it's just completely unrelated to anything.
https://redd.it/1e4k7el
@r_lua
So I'm 16 now and planning on studying CS. So I thought I should start learning a language to help me later on at University. But me and my friend were talking about Making a Roblox game. Roblox uses the language Lua. The problem is I wanted to learn a coding language that would help me in the future. And I just wanted to know if me learning Lua would help me with other coding languages, or it's just completely unrelated to anything.
https://redd.it/1e4k7el
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community