random on lua
i'm using lua to noscript commands on mpv- my goal is to simulate television but only with my fav shows and no ads. i use it to waste time and mostly as a noise background but lately i'm noticing that random is repetitive!
**what i'm doing**: since my attention span is hella short i did some coding to have only 1-2 minutes of each video then jump at the next one in queue (that's the same or different tv series) and re-add the previous to the end so only the selected shows play. it's a bit more complicated than this but i hope i explained myself.
**getting to the point**: when i'm adding a "*random*" video i'm doing `math.randomseed(os.time())` looking for another episode of the same series that could be prev season, current season or next season. most shows have 10 or 20 episodes each season, so i'm having a range of 1-60
but i found that too many times i get the same number (and therefore episode) with several minutes apart each roll. then it changes for each session or after a while, i mean it gets more likely to give me a different series of episodes for each show.
let me be clear, it's not ALWAYS the same but looks like the pseudo random is too much of a pseudo and not enought of a random if that makes any sense XD any advice on how to approach random get function and random seeds? here's how i'm doing it right now (right after setting the seed)
local next_file = files[math.random(#files)]
where files is the collection of \~60 episodes path
thanks for reading have a great day
https://redd.it/1htcbsa
@r_lua
i'm using lua to noscript commands on mpv- my goal is to simulate television but only with my fav shows and no ads. i use it to waste time and mostly as a noise background but lately i'm noticing that random is repetitive!
**what i'm doing**: since my attention span is hella short i did some coding to have only 1-2 minutes of each video then jump at the next one in queue (that's the same or different tv series) and re-add the previous to the end so only the selected shows play. it's a bit more complicated than this but i hope i explained myself.
**getting to the point**: when i'm adding a "*random*" video i'm doing `math.randomseed(os.time())` looking for another episode of the same series that could be prev season, current season or next season. most shows have 10 or 20 episodes each season, so i'm having a range of 1-60
but i found that too many times i get the same number (and therefore episode) with several minutes apart each roll. then it changes for each session or after a while, i mean it gets more likely to give me a different series of episodes for each show.
let me be clear, it's not ALWAYS the same but looks like the pseudo random is too much of a pseudo and not enought of a random if that makes any sense XD any advice on how to approach random get function and random seeds? here's how i'm doing it right now (right after setting the seed)
local next_file = files[math.random(#files)]
where files is the collection of \~60 episodes path
thanks for reading have a great day
https://redd.it/1htcbsa
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lua noscript for streamavatar
I am a new comer in lua coding!
I have managed to connect both of them together using ,streamavatar websocket codes.
I had been trying to use lua noscript that streamavatar to request for "commands" in streamerbot and it's not working no matter how I try it.
I tried asking the developer but they say do it yourself
https://preview.redd.it/yurvx99701be1.png?width=882&format=png&auto=webp&s=7d8844ee7432da75cc8232a1c4ab93db3d8e22a3
https://preview.redd.it/xyd84ab501be1.png?width=716&format=png&auto=webp&s=0758603081d38283d7ffc9ace521a04302017ab0
So I am here asking if anyone can guide me on how it works?
https://redd.it/1htlrn4
@r_lua
I am a new comer in lua coding!
I have managed to connect both of them together using ,streamavatar websocket codes.
I had been trying to use lua noscript that streamavatar to request for "commands" in streamerbot and it's not working no matter how I try it.
I tried asking the developer but they say do it yourself
https://preview.redd.it/yurvx99701be1.png?width=882&format=png&auto=webp&s=7d8844ee7432da75cc8232a1c4ab93db3d8e22a3
https://preview.redd.it/xyd84ab501be1.png?width=716&format=png&auto=webp&s=0758603081d38283d7ffc9ace521a04302017ab0
So I am here asking if anyone can guide me on how it works?
https://redd.it/1htlrn4
@r_lua
Security questions
I want to make a app in lua. (Using love2d) This app will handle sending money through Paypal or other payment methods and withdrawals of the Paypal business account to other PayPal accounts. What are so security practices to do this in the most secure way to ensure that no one will be able to access other users Paypal and take out all of the playpal business account? Should I use a different program like love2d that supports payments?
https://redd.it/1htoz18
@r_lua
I want to make a app in lua. (Using love2d) This app will handle sending money through Paypal or other payment methods and withdrawals of the Paypal business account to other PayPal accounts. What are so security practices to do this in the most secure way to ensure that no one will be able to access other users Paypal and take out all of the playpal business account? Should I use a different program like love2d that supports payments?
https://redd.it/1htoz18
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Feedback on my Dijkstra implementation
While I was doing Advent of Code (in Ruby) last month I found out that I can't implement Dijkstra on the fly (so I didn't managed day 16), so thought it was an excellent opportunity to try it in Lua for a little Love2d-game.
Since it's my first time with this algorithm and with Metatables in Lua I would love some feedback on my code.
The code is written from the Wikipedia explanation of the algorithm.
I'm looking for general feedback, but I have some questions.
\- On line 119 I'm not sure if this `if prev[u\] or u == source then` is really necessary.
\- On line 16 I define the `self.__index`, I tried to make it so that you could make a new Node with known x/y and look it up in a table, but couldn't get it to work. For source/target I needed to use `for k,v in...`in stead of `table[source\]` to find the correct node. That's why I have the two functions `findKey()` and `setTo()`.
I've made a Gist too: https://gist.github.com/Kyrremann/120fcbdd032a7856059960960645e0b9
require("math")
local Dijkstra = {
nodes = {},
}
local Node = {}
function Node:new(x, y)
local node = {
x = x,
y = y,
}
setmetatable(node, self)
self.index = self
return node
end
--- This is for pretty debugging
Node.tostring = function(self)
return self.x .. "," .. self.y
end
Node.eq = function(a, b)
return a.x == b.x and a.y == b.y
end
--- Takes a Tiled map file as input, but any matrix with properties.weight should work.
function Dijkstra:init(map)
for y = 1, #map do
for x = 1, #mapy do
local node = Node:new(x, y)
self.nodesnode = mapyx.properties.weight
end
end
end
--- Finds the distance between two tiles in the map
-- @param source A table with x and y
-- @param target A table with x and y
function Dijkstra:calculate(source, target)
source = Node:new(source.x, source.y)
target = Node:new(target.x, target.y)
local function findKey(t, k)
for key, in pairs(t) do
if key == k then
return key
end
end
end
local function setTo(t, k, v)
local key = findKey(t, k)
if not key then
error("Key: " .. tostring(k) .. " not found")
end
t[key] = v
end
local function shortestDistance(queue, distances)
local found = nil
local min = math.huge
for key, dist in pairs(distances) do
if queue[key] and dist < min then
min = dist
found = key
end
end
if not found then
error("Shortest distance not found")
end
return found
end
local function getNeighbors(node, queue)
local ortho = {
Node:new(node.x, node.y - 1),
Node:new(node.x, node.y + 1),
Node:new(node.x - 1, node.y),
Node:new(node.x + 1, node.y),
}
local neighbors = {}
for i = 1, 4 do
if findKey(queue, ortho[i]) then
table.insert(neighbors, ortho[i])
end
end
return neighbors
end
local dist = {}
local prev = {}
local queue = {}
local queueSize = 0
for k, in pairs(self.nodes) do
distk = math.huge
prevk = nil
queuek = k
queueSize = queueSize + 1
end
setTo(dist, source, 0)
while queueSize > 0 do
local u = shortestDistance(queue, dist)
if u == target then
local path = {}
local weight = 0
if prevu or u == source then
While I was doing Advent of Code (in Ruby) last month I found out that I can't implement Dijkstra on the fly (so I didn't managed day 16), so thought it was an excellent opportunity to try it in Lua for a little Love2d-game.
Since it's my first time with this algorithm and with Metatables in Lua I would love some feedback on my code.
The code is written from the Wikipedia explanation of the algorithm.
I'm looking for general feedback, but I have some questions.
\- On line 119 I'm not sure if this `if prev[u\] or u == source then` is really necessary.
\- On line 16 I define the `self.__index`, I tried to make it so that you could make a new Node with known x/y and look it up in a table, but couldn't get it to work. For source/target I needed to use `for k,v in...`in stead of `table[source\]` to find the correct node. That's why I have the two functions `findKey()` and `setTo()`.
I've made a Gist too: https://gist.github.com/Kyrremann/120fcbdd032a7856059960960645e0b9
require("math")
local Dijkstra = {
nodes = {},
}
local Node = {}
function Node:new(x, y)
local node = {
x = x,
y = y,
}
setmetatable(node, self)
self.index = self
return node
end
--- This is for pretty debugging
Node.tostring = function(self)
return self.x .. "," .. self.y
end
Node.eq = function(a, b)
return a.x == b.x and a.y == b.y
end
--- Takes a Tiled map file as input, but any matrix with properties.weight should work.
function Dijkstra:init(map)
for y = 1, #map do
for x = 1, #mapy do
local node = Node:new(x, y)
self.nodesnode = mapyx.properties.weight
end
end
end
--- Finds the distance between two tiles in the map
-- @param source A table with x and y
-- @param target A table with x and y
function Dijkstra:calculate(source, target)
source = Node:new(source.x, source.y)
target = Node:new(target.x, target.y)
local function findKey(t, k)
for key, in pairs(t) do
if key == k then
return key
end
end
end
local function setTo(t, k, v)
local key = findKey(t, k)
if not key then
error("Key: " .. tostring(k) .. " not found")
end
t[key] = v
end
local function shortestDistance(queue, distances)
local found = nil
local min = math.huge
for key, dist in pairs(distances) do
if queue[key] and dist < min then
min = dist
found = key
end
end
if not found then
error("Shortest distance not found")
end
return found
end
local function getNeighbors(node, queue)
local ortho = {
Node:new(node.x, node.y - 1),
Node:new(node.x, node.y + 1),
Node:new(node.x - 1, node.y),
Node:new(node.x + 1, node.y),
}
local neighbors = {}
for i = 1, 4 do
if findKey(queue, ortho[i]) then
table.insert(neighbors, ortho[i])
end
end
return neighbors
end
local dist = {}
local prev = {}
local queue = {}
local queueSize = 0
for k, in pairs(self.nodes) do
distk = math.huge
prevk = nil
queuek = k
queueSize = queueSize + 1
end
setTo(dist, source, 0)
while queueSize > 0 do
local u = shortestDistance(queue, dist)
if u == target then
local path = {}
local weight = 0
if prevu or u == source then
Gist
My first try to implement Dijkstra's algorithm in Lua. Feedback welcome!
My first try to implement Dijkstra's algorithm in Lua. Feedback welcome! - dijkstra.lua
Feedback on my Dijkstra implementation
While I was doing Advent of Code (in Ruby) last month I found out that I can't implement Dijkstra on the fly (so I didn't managed day 16), so thought it was an excellent opportunity to try it in Lua for a little Love2d-game.
Since it's my first time with this algorithm and with Metatables in Lua I would love some feedback on my code.
The code is written from the Wikipedia explanation of the algorithm.
I'm looking for general feedback, but I have some questions.
\- On line 119 I'm not sure if this \`if prev\[u\] or u == source then\` is really necessary.
\- On line 16 I define the \`self.\_\_index\`, I tried to make it so that you could make a new Node with known x/y and look it up in a table, but couldn't get it to work. For source/target I needed to use \`for k,v in...\`in stead of \`table\[source\]\` to find the correct node. That's why I have the two functions \`findKey()\` and \`setTo()\`.
I've made a Gist too: [https://gist.github.com/Kyrremann/120fcbdd032a7856059960960645e0b9](https://gist.github.com/Kyrremann/120fcbdd032a7856059960960645e0b9)
require("math")
local Dijkstra = {
nodes = {},
}
local Node = {}
function Node:new(x, y)
local node = {
x = x,
y = y,
}
setmetatable(node, self)
self.__index = self
return node
end
--- This is for pretty debugging
Node.__tostring = function(self)
return self.x .. "," .. self.y
end
Node.__eq = function(a, b)
return a.x == b.x and a.y == b.y
end
--- Takes a Tiled map file as input, but any matrix with properties.weight should work.
function Dijkstra:init(map)
for y = 1, #map do
for x = 1, #map[y] do
local node = Node:new(x, y)
self.nodes[node] = map[y][x].properties.weight
end
end
end
--- Finds the distance between two tiles in the map
-- @param source A table with x and y
-- @param target A table with x and y
function Dijkstra:calculate(source, target)
source = Node:new(source.x, source.y)
target = Node:new(target.x, target.y)
local function findKey(t, k)
for key, _ in pairs(t) do
if key == k then
return key
end
end
end
local function setTo(t, k, v)
local key = findKey(t, k)
if not key then
error("Key: " .. tostring(k) .. " not found")
end
t[key] = v
end
local function shortestDistance(queue, distances)
local found = nil
local min = math.huge
for key, dist in pairs(distances) do
if queue[key] and dist < min then
min = dist
found = key
end
end
if not found then
error("Shortest distance not found")
end
return found
end
local function getNeighbors(node, queue)
local ortho = {
Node:new(node.x, node.y - 1),
Node:new(node.x, node.y + 1),
Node:new(node.x - 1, node.y),
Node:new(node.x + 1, node.y),
}
local neighbors = {}
for i = 1, 4 do
if findKey(queue, ortho[i]) then
table.insert(neighbors, ortho[i])
end
end
return neighbors
end
local dist = {}
local prev = {}
local queue = {}
local queueSize = 0
for k, _ in pairs(self.nodes) do
dist[k] = math.huge
prev[k] = nil
queue[k] = k
queueSize = queueSize + 1
end
setTo(dist, source, 0)
while queueSize > 0 do
local u = shortestDistance(queue, dist)
if u == target then
local path = {}
local weight = 0
if prev[u] or u == source then
While I was doing Advent of Code (in Ruby) last month I found out that I can't implement Dijkstra on the fly (so I didn't managed day 16), so thought it was an excellent opportunity to try it in Lua for a little Love2d-game.
Since it's my first time with this algorithm and with Metatables in Lua I would love some feedback on my code.
The code is written from the Wikipedia explanation of the algorithm.
I'm looking for general feedback, but I have some questions.
\- On line 119 I'm not sure if this \`if prev\[u\] or u == source then\` is really necessary.
\- On line 16 I define the \`self.\_\_index\`, I tried to make it so that you could make a new Node with known x/y and look it up in a table, but couldn't get it to work. For source/target I needed to use \`for k,v in...\`in stead of \`table\[source\]\` to find the correct node. That's why I have the two functions \`findKey()\` and \`setTo()\`.
I've made a Gist too: [https://gist.github.com/Kyrremann/120fcbdd032a7856059960960645e0b9](https://gist.github.com/Kyrremann/120fcbdd032a7856059960960645e0b9)
require("math")
local Dijkstra = {
nodes = {},
}
local Node = {}
function Node:new(x, y)
local node = {
x = x,
y = y,
}
setmetatable(node, self)
self.__index = self
return node
end
--- This is for pretty debugging
Node.__tostring = function(self)
return self.x .. "," .. self.y
end
Node.__eq = function(a, b)
return a.x == b.x and a.y == b.y
end
--- Takes a Tiled map file as input, but any matrix with properties.weight should work.
function Dijkstra:init(map)
for y = 1, #map do
for x = 1, #map[y] do
local node = Node:new(x, y)
self.nodes[node] = map[y][x].properties.weight
end
end
end
--- Finds the distance between two tiles in the map
-- @param source A table with x and y
-- @param target A table with x and y
function Dijkstra:calculate(source, target)
source = Node:new(source.x, source.y)
target = Node:new(target.x, target.y)
local function findKey(t, k)
for key, _ in pairs(t) do
if key == k then
return key
end
end
end
local function setTo(t, k, v)
local key = findKey(t, k)
if not key then
error("Key: " .. tostring(k) .. " not found")
end
t[key] = v
end
local function shortestDistance(queue, distances)
local found = nil
local min = math.huge
for key, dist in pairs(distances) do
if queue[key] and dist < min then
min = dist
found = key
end
end
if not found then
error("Shortest distance not found")
end
return found
end
local function getNeighbors(node, queue)
local ortho = {
Node:new(node.x, node.y - 1),
Node:new(node.x, node.y + 1),
Node:new(node.x - 1, node.y),
Node:new(node.x + 1, node.y),
}
local neighbors = {}
for i = 1, 4 do
if findKey(queue, ortho[i]) then
table.insert(neighbors, ortho[i])
end
end
return neighbors
end
local dist = {}
local prev = {}
local queue = {}
local queueSize = 0
for k, _ in pairs(self.nodes) do
dist[k] = math.huge
prev[k] = nil
queue[k] = k
queueSize = queueSize + 1
end
setTo(dist, source, 0)
while queueSize > 0 do
local u = shortestDistance(queue, dist)
if u == target then
local path = {}
local weight = 0
if prev[u] or u == source then
Gist
My first try to implement Dijkstra's algorithm in Lua. Feedback welcome!
My first try to implement Dijkstra's algorithm in Lua. Feedback welcome! - dijkstra.lua
while prev[u] do
table.insert(path, 1, u)
weight = weight + dist[u]
u = prev[u]
end
end
return path, weight
end
queue[u] = nil
queueSize = queueSize - 1
local neighbors = getNeighbors(u, queue)
for _, n in pairs(neighbors) do
local key = findKey(dist, n)
if not key then
error("Key: " .. tostring(key) .. " not found")
end
local alt = dist[u] + self.nodes[key]
if alt < dist[key] then
dist[key] = alt
prev[key] = u
end
end
end
error("Path not found")
end
return Dijkstra
https://redd.it/1htr0jf
@r_lua
table.insert(path, 1, u)
weight = weight + dist[u]
u = prev[u]
end
end
return path, weight
end
queue[u] = nil
queueSize = queueSize - 1
local neighbors = getNeighbors(u, queue)
for _, n in pairs(neighbors) do
local key = findKey(dist, n)
if not key then
error("Key: " .. tostring(key) .. " not found")
end
local alt = dist[u] + self.nodes[key]
if alt < dist[key] then
dist[key] = alt
prev[key] = u
end
end
end
error("Path not found")
end
return Dijkstra
https://redd.it/1htr0jf
@r_lua
Reddit
From the lua community on Reddit: Feedback on my Dijkstra implementation
Explore this post and more from the lua community
How to reset a counter back to 0 in lua?
i am very new to lua and i am currently trying to create a program for my mc turtle, i have a if statement that tells it to count the steps it takes before doing a action. But after it has performed that action it should reset the counter to 0 again.
Not sure what i am doing wrong but it is not resetting it like it should.
local function Mine_Stairs()
local stepCount = 0
local torchCount = 0
while true do
turtle.dig()
if turtle.forward() then
stepCount = stepCount + 1
torchCount = torchCount + 1
turtle.digUp()
turtle.digDown()
if torchCount % 5 == 0 then --counts how many steps it has taken before it should place a torch.
local itemDetail = turtle.getItemDetail(16)
if itemDetail and itemDetail.name == "minecraft:torch" then
turtle.select(16)
turtle.forward()
turtle.turnRight()
turtle.turnRight()
turtle.place()
print("Torch placed.")
turtle.turnLeft()
turtle.turnLeft()
if count == torchCount and stepCount == 1 then
torchCount = torchCount - 1
stepCount = stepCount - 1
end
else
print("Out of torches!")
end
end
if stepCount % 3 == 0 then --counts how many steps it ahs taken before it should rotate to the right.
turtle.turnRight()
stepCount = 0
end
turtle.down()
else
print("Obstacle detected. Stopping.")
break
end
end
end
Mine_Stairs()
https://redd.it/1huynaz
@r_lua
i am very new to lua and i am currently trying to create a program for my mc turtle, i have a if statement that tells it to count the steps it takes before doing a action. But after it has performed that action it should reset the counter to 0 again.
Not sure what i am doing wrong but it is not resetting it like it should.
local function Mine_Stairs()
local stepCount = 0
local torchCount = 0
while true do
turtle.dig()
if turtle.forward() then
stepCount = stepCount + 1
torchCount = torchCount + 1
turtle.digUp()
turtle.digDown()
if torchCount % 5 == 0 then --counts how many steps it has taken before it should place a torch.
local itemDetail = turtle.getItemDetail(16)
if itemDetail and itemDetail.name == "minecraft:torch" then
turtle.select(16)
turtle.forward()
turtle.turnRight()
turtle.turnRight()
turtle.place()
print("Torch placed.")
turtle.turnLeft()
turtle.turnLeft()
if count == torchCount and stepCount == 1 then
torchCount = torchCount - 1
stepCount = stepCount - 1
end
else
print("Out of torches!")
end
end
if stepCount % 3 == 0 then --counts how many steps it ahs taken before it should rotate to the right.
turtle.turnRight()
stepCount = 0
end
turtle.down()
else
print("Obstacle detected. Stopping.")
break
end
end
end
Mine_Stairs()
https://redd.it/1huynaz
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
why does Pairs sometimes puts it in order, but sometimes not?
I understand that Pairs() isn't guaranteed to go through "arrays" in order.
I have 3 tables below that are all numerically indexed starting from 1. I used different ways of making each table. I just want to know why tables B and C are in order with Pairs, but table A is NOT in order. (output is at the bottom of the post) All 3 tables are using pairs
For table A, does it have anything to do with explicitly defining the index number?
The IDE is visual studio Code.
A = {
[1] = "one",
[2] = "two",
[3] = "three",
[4] = "four"
}
for i, v in pairs(A) do
print(i, v)
end
B = {"a", "b", "c", "d"}
for i, v in pairs(B) do
print(i, v)
end
C = {}
for i=1, 9 do
C[i] = i*10
end
for i, v in pairs(C) do
print(i, v)
end
Output:
3 three
1 one
2 two
4 four
1 a
2 b
3 c
4 d
1 10
2 20
3 30
4 40
5 50
6 60
7 70
8 80
9 90
https://redd.it/1hvd7fr
@r_lua
I understand that Pairs() isn't guaranteed to go through "arrays" in order.
I have 3 tables below that are all numerically indexed starting from 1. I used different ways of making each table. I just want to know why tables B and C are in order with Pairs, but table A is NOT in order. (output is at the bottom of the post) All 3 tables are using pairs
For table A, does it have anything to do with explicitly defining the index number?
The IDE is visual studio Code.
A = {
[1] = "one",
[2] = "two",
[3] = "three",
[4] = "four"
}
for i, v in pairs(A) do
print(i, v)
end
B = {"a", "b", "c", "d"}
for i, v in pairs(B) do
print(i, v)
end
C = {}
for i=1, 9 do
C[i] = i*10
end
for i, v in pairs(C) do
print(i, v)
end
Output:
3 three
1 one
2 two
4 four
1 a
2 b
3 c
4 d
1 10
2 20
3 30
4 40
5 50
6 60
7 70
8 80
9 90
https://redd.it/1hvd7fr
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Roblox Script not Working HELP!!
I am developing a game where you can tag a player on the other team as long as they are on your side and when tagged the other player is killed then respawned to a "jail" I have a remote event named "TagEvent" set up and the teams "Frosting" and "Dough" are set up as well with their separate spawnpoints called "FrostingTagged" and "DoughTagged". Also, the part where they get tagged is noscriptd is called "FrostingTagArea" and "DoughTagArea". These are all setup you can touch them and query them all as well. I've used Ai to help me, and it has done nothing to help. I am truly lost. Any ideas are appreciated. When i do a local server test the only two things that show up in the output are something along the lines of "no player found" and "Player 1 is attempting to tag Player 2". Ill include pictures of both of the noscripts.
Local Script
Server
Server
Server
https://redd.it/1hvcop3
@r_lua
I am developing a game where you can tag a player on the other team as long as they are on your side and when tagged the other player is killed then respawned to a "jail" I have a remote event named "TagEvent" set up and the teams "Frosting" and "Dough" are set up as well with their separate spawnpoints called "FrostingTagged" and "DoughTagged". Also, the part where they get tagged is noscriptd is called "FrostingTagArea" and "DoughTagArea". These are all setup you can touch them and query them all as well. I've used Ai to help me, and it has done nothing to help. I am truly lost. Any ideas are appreciated. When i do a local server test the only two things that show up in the output are something along the lines of "no player found" and "Player 1 is attempting to tag Player 2". Ill include pictures of both of the noscripts.
Local Script
Server
Server
Server
https://redd.it/1hvcop3
@r_lua
Lua with Manual memory management
Hi everyone!
I’ve started experimenting with the Lua API in C, and I thought there was no better way to challenge myself than by implementing a manual memory management system in Lua.
I just wanted to share the current state of the project. As of now, it’s not working as smoothly as I’d like. Currently, you still need to explicitly use the garbage collector (GC) to delete freed pointers, and I’ve only implemented integer types so far. But hey, I’m closer than I was yesterday, so I’ll keep improving the project.
Feel free to check it out, discuss, critique my code, open issues, or make pull requests (PRs).
At the moment, it doesn’t include a method to compile the library or even a simple release, as, like I mentioned, it’s not fully functional yet.
For anyone wondering: Why??????
Well, I just wanted to do it. There’s no particular scenario where this would be better than Lua’s original garbage collector—especially considering you can trigger the GC manually—but hey, I’m just a simple guy who likes to mess around with things.
I hope some of you find the idea interesting.
GitHub Repository: Unsafe-Lua
https://redd.it/1hvra76
@r_lua
Hi everyone!
I’ve started experimenting with the Lua API in C, and I thought there was no better way to challenge myself than by implementing a manual memory management system in Lua.
I just wanted to share the current state of the project. As of now, it’s not working as smoothly as I’d like. Currently, you still need to explicitly use the garbage collector (GC) to delete freed pointers, and I’ve only implemented integer types so far. But hey, I’m closer than I was yesterday, so I’ll keep improving the project.
Feel free to check it out, discuss, critique my code, open issues, or make pull requests (PRs).
At the moment, it doesn’t include a method to compile the library or even a simple release, as, like I mentioned, it’s not fully functional yet.
For anyone wondering: Why??????
Well, I just wanted to do it. There’s no particular scenario where this would be better than Lua’s original garbage collector—especially considering you can trigger the GC manually—but hey, I’m just a simple guy who likes to mess around with things.
I hope some of you find the idea interesting.
GitHub Repository: Unsafe-Lua
https://redd.it/1hvra76
@r_lua
GitHub
GitHub - Ajotah98/Unsafe-Lua
Contribute to Ajotah98/Unsafe-Lua development by creating an account on GitHub.
Problems With Sol and the Lua Library
Hello! I'm currently setting up an SDL project and wanted to use Lua to some extent. However, I'm having issues including Sol in the project. I haven't had problems with any of the other libraries I'm using, just Sol-Lua specifically. I've included the appropriate Include and Library paths. If you have any experience with this library, could you help me figure out what I could be doing wrong? Any help would be greatly appreciated.
https://preview.redd.it/6xccupiqtkbe1.jpg?width=690&format=pjpg&auto=webp&s=bfb4ed9972478dff87eff0d937812cc1ae960c46
https://preview.redd.it/ob7bspiqtkbe1.jpg?width=382&format=pjpg&auto=webp&s=de93af5063745d80ce441824d3687edce65caa4f
https://preview.redd.it/gaj84riqtkbe1.jpg?width=387&format=pjpg&auto=webp&s=41207f7d64fa33ba55d2540ae8704f9c31ae5441
https://preview.redd.it/nhvz1riqtkbe1.jpg?width=470&format=pjpg&auto=webp&s=4854db036f9fc989fb7b585671eec7f79ae72ff6
https://redd.it/1hvuitn
@r_lua
Hello! I'm currently setting up an SDL project and wanted to use Lua to some extent. However, I'm having issues including Sol in the project. I haven't had problems with any of the other libraries I'm using, just Sol-Lua specifically. I've included the appropriate Include and Library paths. If you have any experience with this library, could you help me figure out what I could be doing wrong? Any help would be greatly appreciated.
https://preview.redd.it/6xccupiqtkbe1.jpg?width=690&format=pjpg&auto=webp&s=bfb4ed9972478dff87eff0d937812cc1ae960c46
https://preview.redd.it/ob7bspiqtkbe1.jpg?width=382&format=pjpg&auto=webp&s=de93af5063745d80ce441824d3687edce65caa4f
https://preview.redd.it/gaj84riqtkbe1.jpg?width=387&format=pjpg&auto=webp&s=41207f7d64fa33ba55d2540ae8704f9c31ae5441
https://preview.redd.it/nhvz1riqtkbe1.jpg?width=470&format=pjpg&auto=webp&s=4854db036f9fc989fb7b585671eec7f79ae72ff6
https://redd.it/1hvuitn
@r_lua
Im trying to make my dude teleport forward a few seconds after pressing one
me my brother a friend of mine and one of my friend's friends are making a roblox battlegrounds game. even tho my friend and his friend are the ones supposed to be coding, they're not really helping fix the move. basically the dude goes into a running stance, then flashes forward and kicks. however, right now all he does is run forward. ples tell me how im supposed to do it
https://redd.it/1hw3elt
@r_lua
me my brother a friend of mine and one of my friend's friends are making a roblox battlegrounds game. even tho my friend and his friend are the ones supposed to be coding, they're not really helping fix the move. basically the dude goes into a running stance, then flashes forward and kicks. however, right now all he does is run forward. ples tell me how im supposed to do it
https://redd.it/1hw3elt
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Announcing Astra - LuaJIT webserver built on top of Rust
Hey everyone! Hope the new year has been chill so far.
I am very happy to announce Astra (https://astra.arkforge.net), a small webserver built on top of Rust + Axum for LuaJIT (Lua PUC versions coming soon). The goal is to have a fault-tolerant, fast, memory safe, and auto scaling web server while at the same time being insanely easy to use and extend. This project is mainly used so far within our company for some products and sees development wherever we find need for.
Some examples from the README:
-- Routes are defined through these route functions
-- route functions need a path and a callback
Astra.get("/", function()
-- they may have a return too (optional)
return "hello from default Astra instance!"
end)
-- Local and global variables can be mutated at any
-- time as the callbacks are ran on runtime.
local counter = 0
Astra.get("/count", function()
counter = counter + 1
-- and also can return JSON
return { countervalue = counter }
end)
-- The callback function offers requests and responses
-- arguments which can be used to consume incoming data
-- and shape outgoinging structure
Astra.get("/", function(req, res)
-- set header code
res:setstatuscode(300)
-- set headers
res:setheader("header-key", "header-value")
-- read the request body
print(req:body():text())
return "Responding with Code 300 cuz why not"
end)
There are also a lot of utilities provided as well, such as table schema validation (as an alternative to having typed tables), HTTP client, PostgreSQL driver, async tasks, markup language parsing such as JSON, ... and with more to come in the future such as templating. There are also some functionality missing as of yet, such as websockets, which will come with time.
This webserver is packaged as a single binary that you can just download on server of your local machine (prebuilt binary releases for windows and linux x64 are available) and can generally assume what works locally will work on the cloud as well since they both will use the same binary and instructions. The binary also packages the bundled lua code that includes some utilities and the Astra's own type definitions for help with intellisense in some cases.
Enjoy!
https://redd.it/1hwfmz5
@r_lua
Hey everyone! Hope the new year has been chill so far.
I am very happy to announce Astra (https://astra.arkforge.net), a small webserver built on top of Rust + Axum for LuaJIT (Lua PUC versions coming soon). The goal is to have a fault-tolerant, fast, memory safe, and auto scaling web server while at the same time being insanely easy to use and extend. This project is mainly used so far within our company for some products and sees development wherever we find need for.
Some examples from the README:
-- Routes are defined through these route functions
-- route functions need a path and a callback
Astra.get("/", function()
-- they may have a return too (optional)
return "hello from default Astra instance!"
end)
-- Local and global variables can be mutated at any
-- time as the callbacks are ran on runtime.
local counter = 0
Astra.get("/count", function()
counter = counter + 1
-- and also can return JSON
return { countervalue = counter }
end)
-- The callback function offers requests and responses
-- arguments which can be used to consume incoming data
-- and shape outgoinging structure
Astra.get("/", function(req, res)
-- set header code
res:setstatuscode(300)
-- set headers
res:setheader("header-key", "header-value")
-- read the request body
print(req:body():text())
return "Responding with Code 300 cuz why not"
end)
There are also a lot of utilities provided as well, such as table schema validation (as an alternative to having typed tables), HTTP client, PostgreSQL driver, async tasks, markup language parsing such as JSON, ... and with more to come in the future such as templating. There are also some functionality missing as of yet, such as websockets, which will come with time.
This webserver is packaged as a single binary that you can just download on server of your local machine (prebuilt binary releases for windows and linux x64 are available) and can generally assume what works locally will work on the cloud as well since they both will use the same binary and instructions. The binary also packages the bundled lua code that includes some utilities and the Astra's own type definitions for help with intellisense in some cases.
Enjoy!
https://redd.it/1hwfmz5
@r_lua
astra.arkforge.net
🔥 Blazingly Fast 🔥 lua runtime
Good practices - (type|nil) vs (type) passed in an if statement
Hello, which of below cases is a good practice in lua?
case 1:
local function foo(arg, bool)
bar(arg)
-- passing bool: boolean|nil
if bool then baz() end
end
case 2:
local function foo(arg, bool)
bar(arg)
bool = (bool ~= nil and bool)
-- passing bool: boolean
if bool then baz() end
end
https://redd.it/1hwkf0f
@r_lua
Hello, which of below cases is a good practice in lua?
case 1:
local function foo(arg, bool)
bar(arg)
-- passing bool: boolean|nil
if bool then baz() end
end
case 2:
local function foo(arg, bool)
bar(arg)
bool = (bool ~= nil and bool)
-- passing bool: boolean
if bool then baz() end
end
https://redd.it/1hwkf0f
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
MPV Lua Script to cycle through specific audio and subs of a video
Here is an example:
A video have 5 audio in it (English, Japanese, Spanish, German, French) and it also have 5 subs in it (English, Japanese, Spanish, German, French).
With the above example, how can I cycle to specific audio and subs while skipping the other ones? I'm only interested in English, Japanese and Spanish, which means I don't want to cycle through German and French and I want to get rid of those languages when I'm cycling with the hotkey, how can I do this? is there a Lua noscript that can make this happen?
Note: It needs to be able to cycle the subnoscript inside the "Subs" folder as well as long as the subnoscript has the same name as the video.
https://redd.it/1hwoy6t
@r_lua
Here is an example:
A video have 5 audio in it (English, Japanese, Spanish, German, French) and it also have 5 subs in it (English, Japanese, Spanish, German, French).
With the above example, how can I cycle to specific audio and subs while skipping the other ones? I'm only interested in English, Japanese and Spanish, which means I don't want to cycle through German and French and I want to get rid of those languages when I'm cycling with the hotkey, how can I do this? is there a Lua noscript that can make this happen?
Note: It needs to be able to cycle the subnoscript inside the "Subs" folder as well as long as the subnoscript has the same name as the video.
https://redd.it/1hwoy6t
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
MPV.net (media player) On Screen Controller Lua Script help
I have this noscript that hides the OSC in fullscreen but it's always visible when I exit fullscreen:
-- Keeps the OSC visible in windowed mode and hides it in fullscreen
mp.observeproperty("fullscreen", "bool", function(, isfullscreen)
if isfullscreen then
-- Hide the OSC in fullscreen mode
mp.command("noscript-message osc-visibility auto")
else
-- Always show the OSC in windowed mode
mp.command("noscript-message osc-visibility always")
end
end)
The noscript works fine but there is a problem, when I enter fullscreen I get an on-screen text saying "OSC visibility: Auto", and when I exit fullscreen it says "OSC visibility: Always", how can I modify the above noscript to remove those 2 annoying on-screen text messages?
https://redd.it/1hwosxn
@r_lua
I have this noscript that hides the OSC in fullscreen but it's always visible when I exit fullscreen:
-- Keeps the OSC visible in windowed mode and hides it in fullscreen
mp.observeproperty("fullscreen", "bool", function(, isfullscreen)
if isfullscreen then
-- Hide the OSC in fullscreen mode
mp.command("noscript-message osc-visibility auto")
else
-- Always show the OSC in windowed mode
mp.command("noscript-message osc-visibility always")
end
end)
The noscript works fine but there is a problem, when I enter fullscreen I get an on-screen text saying "OSC visibility: Auto", and when I exit fullscreen it says "OSC visibility: Always", how can I modify the above noscript to remove those 2 annoying on-screen text messages?
https://redd.it/1hwosxn
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Is there a Lua noscript to have the Audio/Sub icon show a mini-menu?
I'm using MPV.net, is there a way to make the Audio/Sub icon of the player show a menu with the available audio and subnoscripts? With the default behavior, clicking these icons cycles through them which is a pain because if a video has 10 audio or subnoscripts it will cycle through each one of them so it's counter-productive for me.
Instead of the default behavior, I want to click on it, open a mini-menu and select my specific audio or subnoscripts and not cycle through them. Is there a Lua noscript that can make this happen?
https://preview.redd.it/tqlh8crgwtbe1.jpg?width=932&format=pjpg&auto=webp&s=9fefec81016d993f9a58f04d09f396cfccedb838
https://redd.it/1hwtuxi
@r_lua
I'm using MPV.net, is there a way to make the Audio/Sub icon of the player show a menu with the available audio and subnoscripts? With the default behavior, clicking these icons cycles through them which is a pain because if a video has 10 audio or subnoscripts it will cycle through each one of them so it's counter-productive for me.
Instead of the default behavior, I want to click on it, open a mini-menu and select my specific audio or subnoscripts and not cycle through them. Is there a Lua noscript that can make this happen?
https://preview.redd.it/tqlh8crgwtbe1.jpg?width=932&format=pjpg&auto=webp&s=9fefec81016d993f9a58f04d09f396cfccedb838
https://redd.it/1hwtuxi
@r_lua
GitHub
GitHub - mpvnet-player/mpv.net: 🎞 mpv.net is a media player for Windows with a modern GUI.
🎞 mpv.net is a media player for Windows with a modern GUI. - mpvnet-player/mpv.net
Make an object face the camera (roblox studio)
I'm pretty new to coding Lua, so I have like no clue how to do anything. I'm trying to get an object to face towards the camera at all times, and I've gone into countless forums and things where people asked a similar question, but I can't find anything that actually works or even has an effect on the object for that matter. Any Suggestions?
I would also like to know somewhere I can get lessons on coding with Lua.
https://redd.it/1hwt60i
@r_lua
I'm pretty new to coding Lua, so I have like no clue how to do anything. I'm trying to get an object to face towards the camera at all times, and I've gone into countless forums and things where people asked a similar question, but I can't find anything that actually works or even has an effect on the object for that matter. Any Suggestions?
I would also like to know somewhere I can get lessons on coding with Lua.
https://redd.it/1hwt60i
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community