Is this a good way of trimming user input? There's an option to paste from clipboard as well and that goes over the limit
https://redd.it/1ic2ghs
@r_lua
https://redd.it/1ic2ghs
@r_lua
Help understanding tables
Hi all,
I'm writing Lua for a boat's navigation computer in the game Stormworks. The computer takes coordinate inputs from multiple sources (internal gps, transponder locator, radar, keyboard) and writes them to the indices of table p. Each index of p represents a point on the map, the rows within contain data about that point, for example p[9\][x\]=boat's x coordinate, p[9\][y\]=boat's y coordinate, p[9\][db\]=boat's distance to boat (will always be 0), p[9\][id\]="b". Once the table has been populated I want to remove any index from the table where p[i\][x\]==nil so that I don't need to deal with them when rendering the points on a map. I also want to sort them by db for easy readability in the UI. If my understanding of Lua is correct (low chance I know) p will effectively always have some nil x/y values associated with a non nil index because I need to declare each row of p[i\] before I can set its coordinates. With all that in mind, can someone please explain the behavior of my code in the following cases:
1. https://onecompiler.com/lua/437eb2qbg in this instance I have left out the table.remove() function. Sorting works as expected. This is just here to compare against the next two examples
2. https://onecompiler.com/lua/437e8w65y here I try to remove indices with nil x values before the sorting step. I don't know why a nil index is being called by the getDist function, it seems to me that the table should have no nil values after the removal step, so what gives?
3. https://onecompiler.com/lua/437eb7yn8 here I remove indices with nil x value after the sort. You can see that three of the nil values have been removed, three have remained. I assigned p[i\][id\] here in the radar loop to see if the values that get dropped are random. Strangely, it appears that r4, r5, and r7 always get removed.
Questions I have anticipated:
Q: Does this post violate rule 8?
A: No, Stormworks gives players the ability to write Lua for their components in an in game editor, this is intended functionality by the devs.
Q. Surely someone has made a working navigation computer in Stormworks, why not just download someone else's from the workshop?
A. I would rather die.
Q. Why does getDist() return 999999999 for nil parameters instead of nil?
A. returning nil breaks my sort. I tried to handle nils in the sort function but that did not work at all. If you have pointers here I would be very happy to hear them. The map is way smaller than 999999999 so I'll never mistake that value for real data.
Q. Ok then why don't you just set all nil values as 999999999 then?
A. It seems lazy. That's what I will do if ya'll think it's the right way of handling this problem, but it feels very unga-bunga to me. Like I said above I'd rather never return a dummy value, I just don't know enough yet to avoid it
Thanks in advance! This is my first post here, hopefully the onecompiler links properly abide by rule 5.
>Edit: Spelling
https://redd.it/1ic8196
@r_lua
Hi all,
I'm writing Lua for a boat's navigation computer in the game Stormworks. The computer takes coordinate inputs from multiple sources (internal gps, transponder locator, radar, keyboard) and writes them to the indices of table p. Each index of p represents a point on the map, the rows within contain data about that point, for example p[9\][x\]=boat's x coordinate, p[9\][y\]=boat's y coordinate, p[9\][db\]=boat's distance to boat (will always be 0), p[9\][id\]="b". Once the table has been populated I want to remove any index from the table where p[i\][x\]==nil so that I don't need to deal with them when rendering the points on a map. I also want to sort them by db for easy readability in the UI. If my understanding of Lua is correct (low chance I know) p will effectively always have some nil x/y values associated with a non nil index because I need to declare each row of p[i\] before I can set its coordinates. With all that in mind, can someone please explain the behavior of my code in the following cases:
1. https://onecompiler.com/lua/437eb2qbg in this instance I have left out the table.remove() function. Sorting works as expected. This is just here to compare against the next two examples
2. https://onecompiler.com/lua/437e8w65y here I try to remove indices with nil x values before the sorting step. I don't know why a nil index is being called by the getDist function, it seems to me that the table should have no nil values after the removal step, so what gives?
3. https://onecompiler.com/lua/437eb7yn8 here I remove indices with nil x value after the sort. You can see that three of the nil values have been removed, three have remained. I assigned p[i\][id\] here in the radar loop to see if the values that get dropped are random. Strangely, it appears that r4, r5, and r7 always get removed.
Questions I have anticipated:
Q: Does this post violate rule 8?
A: No, Stormworks gives players the ability to write Lua for their components in an in game editor, this is intended functionality by the devs.
Q. Surely someone has made a working navigation computer in Stormworks, why not just download someone else's from the workshop?
A. I would rather die.
Q. Why does getDist() return 999999999 for nil parameters instead of nil?
A. returning nil breaks my sort. I tried to handle nils in the sort function but that did not work at all. If you have pointers here I would be very happy to hear them. The map is way smaller than 999999999 so I'll never mistake that value for real data.
Q. Ok then why don't you just set all nil values as 999999999 then?
A. It seems lazy. That's what I will do if ya'll think it's the right way of handling this problem, but it feels very unga-bunga to me. Like I said above I'd rather never return a dummy value, I just don't know enough yet to avoid it
Thanks in advance! This is my first post here, hopefully the onecompiler links properly abide by rule 5.
>Edit: Spelling
https://redd.it/1ic8196
@r_lua
How to Install Lua on Windows
If you're still stuck on Windows like me, these steps might help you install Lua. At least, they worked for me.
1. Download the Windows x64 Executables (or x86, if applicable) for Lua from https://luabinaries.sourceforge.net/download.html
2. Extract the contents into a folder named "lua"
3. Move the "lua" folder to "C:\\Program Files" (or "C:\\Program Files (x86)" if you downloaded the x86 version)
4. Inside the folder, rename "lua53.exe" to "lua.exe" so that you can run it simply as `lua` instead of `lua53` (You might have a newer version, but I am using LuaBinaries 5.3.6).
5. Copy the folder path ("C:\\Program Files\\lua" or "C:\\Program Files (x86)\\lua") and add it to the PATH environment variable. (You know how to do this, right?)
6. Verify the installation by opening the Command Prompt and running: `lua`
https://redd.it/1icuoql
@r_lua
If you're still stuck on Windows like me, these steps might help you install Lua. At least, they worked for me.
1. Download the Windows x64 Executables (or x86, if applicable) for Lua from https://luabinaries.sourceforge.net/download.html
2. Extract the contents into a folder named "lua"
3. Move the "lua" folder to "C:\\Program Files" (or "C:\\Program Files (x86)" if you downloaded the x86 version)
4. Inside the folder, rename "lua53.exe" to "lua.exe" so that you can run it simply as `lua` instead of `lua53` (You might have a newer version, but I am using LuaBinaries 5.3.6).
5. Copy the folder path ("C:\\Program Files\\lua" or "C:\\Program Files (x86)\\lua") and add it to the PATH environment variable. (You know how to do this, right?)
6. Verify the installation by opening the Command Prompt and running: `lua`
https://redd.it/1icuoql
@r_lua
Can anyone explain why this code doesnt work ? i wrote the code in the newest lua version.
local userpassword = {}
local generatedpassword = {}
function randpasswordgenerate()
repeat
table.insert(generatedpassword,table.concat(string.char(math.random(60,116))))
until userpasswordmath.random(8, 16) ~= nil
end
userpassword = generatedpassword
https://redd.it/1icywvh
@r_lua
local userpassword = {}
local generatedpassword = {}
function randpasswordgenerate()
repeat
table.insert(generatedpassword,table.concat(string.char(math.random(60,116))))
until userpasswordmath.random(8, 16) ~= nil
end
userpassword = generatedpassword
https://redd.it/1icywvh
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I am Interested in Learning lua
i am interested in learning lua but don't know where to start. what should i learn first and in what order should i learn first in lua and for context i know java java noscript python and html. if that make's it easier for choosing how i should learn thank you for considering in advance
https://redd.it/1id3nex
@r_lua
i am interested in learning lua but don't know where to start. what should i learn first and in what order should i learn first in lua and for context i know java java noscript python and html. if that make's it easier for choosing how i should learn thank you for considering in advance
https://redd.it/1id3nex
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Ban posts asking for help to learn Lua
There's been too many posts like "help learn lua" "best way to learn lua" "where do I learn"
God damn. 50% of the posts are asking the exact same. All you have to do is search this subreddit before posting a question.
You will find plenty of online resources for learning. Don't flood this subreddit with those questions. Ask questions that haven't been asked before, that way you add value to this subreddit.
Mods, do something about it.
https://redd.it/1idin6j
@r_lua
There's been too many posts like "help learn lua" "best way to learn lua" "where do I learn"
God damn. 50% of the posts are asking the exact same. All you have to do is search this subreddit before posting a question.
You will find plenty of online resources for learning. Don't flood this subreddit with those questions. Ask questions that haven't been asked before, that way you add value to this subreddit.
Mods, do something about it.
https://redd.it/1idin6j
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Book
Are there any books for lua? (Price 10 - 20$) I love readinng books and most of the time i remember alot from them so reading them could help me learn the language.
https://redd.it/1iduhhu
@r_lua
Are there any books for lua? (Price 10 - 20$) I love readinng books and most of the time i remember alot from them so reading them could help me learn the language.
https://redd.it/1iduhhu
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Mesh modification?
I want to make a little noscript that takes in an FBX mesh (or other 3d model type) and assuming it is a cube, each side would represent (what i call) 1 "unit." It would then generate and save all size variations of this mesh going from 1x1x1 units (the starting size) to 8x8x8. In the end, the folder that had the 1x1x1 mesh now has all 512 different size variations of it. If the input were a wedge/slope with the same bounding box, it would also output all size variations of it, so it isnt limited to cubes.
But what can I do to modify the mesh in the first place? I cant find any luarocks modules to use, (or they exist and im not looking closely) nor do I know how to do it manually.
https://redd.it/1idw71u
@r_lua
I want to make a little noscript that takes in an FBX mesh (or other 3d model type) and assuming it is a cube, each side would represent (what i call) 1 "unit." It would then generate and save all size variations of this mesh going from 1x1x1 units (the starting size) to 8x8x8. In the end, the folder that had the 1x1x1 mesh now has all 512 different size variations of it. If the input were a wedge/slope with the same bounding box, it would also output all size variations of it, so it isnt limited to cubes.
But what can I do to modify the mesh in the first place? I cant find any luarocks modules to use, (or they exist and im not looking closely) nor do I know how to do it manually.
https://redd.it/1idw71u
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Why people laugh of lua so much?
Recently i see more and more people making fun out of lua and saying it is not proper language. I fell like as if lua was even more laughed of than Python.
https://redd.it/1idx0yq
@r_lua
Recently i see more and more people making fun out of lua and saying it is not proper language. I fell like as if lua was even more laughed of than Python.
https://redd.it/1idx0yq
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Hello world final boss
local program = [[
\++++++++[>++++[>++>+++>+++>+<<<<-\]>+>+>->>+[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
\]\]
local tape = {}
local tapePointer = 1
local output = ""
for i = 1, 30000 do
tape[i\] = 0
end
local function getTapeValue()
return tape[tapePointer\] or 0
end
local function setTapeValue(value)
tape[tapePointer\] = value % 256
end
local function interpretBF(code)
local codePointer = 1
local codeLength = #code
local jumpTable = {}
local openBrackets = {}
for i = 1, codeLength do
local instruction = code:sub(i, i)
if instruction == "[" then
table.insert(openBrackets, i)
elseif instruction == "\]" then
local startPos = table.remove(openBrackets)
if startPos then
jumpTable[startPos\] = i
jumpTable[i\] = startPos
end
end
end
while codePointer <= codeLength do
local instruction = code:sub(codePointer, codePointer)
if instruction == ">" then
tapePointer = tapePointer + 1
elseif instruction == "<" then
tapePointer = math.max(tapePointer - 1, 1)
elseif instruction == "+" then
setTapeValue(getTapeValue() + 1)
elseif instruction == "-" then
setTapeValue(getTapeValue() - 1)
elseif instruction == "." then
output = output .. string.char(getTapeValue())
elseif instruction == "[" and getTapeValue() == 0 then
codePointer = jumpTable[codePointer\]
elseif instruction == "\]" and getTapeValue() \~= 0 then
codePointer = jumpTable[codePointer\]
end
codePointer = codePointer + 1
end
end
pcall(function() interpretBF(program) end)
print(output)
for i = 1, (200 - 55) do
print("")
end
https://redd.it/1iedrtj
@r_lua
local program = [[
\++++++++[>++++[>++>+++>+++>+<<<<-\]>+>+>->>+[<\]<-\]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
\]\]
local tape = {}
local tapePointer = 1
local output = ""
for i = 1, 30000 do
tape[i\] = 0
end
local function getTapeValue()
return tape[tapePointer\] or 0
end
local function setTapeValue(value)
tape[tapePointer\] = value % 256
end
local function interpretBF(code)
local codePointer = 1
local codeLength = #code
local jumpTable = {}
local openBrackets = {}
for i = 1, codeLength do
local instruction = code:sub(i, i)
if instruction == "[" then
table.insert(openBrackets, i)
elseif instruction == "\]" then
local startPos = table.remove(openBrackets)
if startPos then
jumpTable[startPos\] = i
jumpTable[i\] = startPos
end
end
end
while codePointer <= codeLength do
local instruction = code:sub(codePointer, codePointer)
if instruction == ">" then
tapePointer = tapePointer + 1
elseif instruction == "<" then
tapePointer = math.max(tapePointer - 1, 1)
elseif instruction == "+" then
setTapeValue(getTapeValue() + 1)
elseif instruction == "-" then
setTapeValue(getTapeValue() - 1)
elseif instruction == "." then
output = output .. string.char(getTapeValue())
elseif instruction == "[" and getTapeValue() == 0 then
codePointer = jumpTable[codePointer\]
elseif instruction == "\]" and getTapeValue() \~= 0 then
codePointer = jumpTable[codePointer\]
end
codePointer = codePointer + 1
end
end
pcall(function() interpretBF(program) end)
print(output)
for i = 1, (200 - 55) do
print("")
end
https://redd.it/1iedrtj
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
How to launch 2 functions with one luadrawhookpost command.
Hello everyone,
I have been working for about an hour with chatgpt and it simple cannot do this.
I have a .lua file that contains two functions named main and main2
I have a config file for the linux app Conky that launches this .lua via the code:
`-- Lua Load`
`luaload = '/home/logansfury/.conky2/horiz.lua',
I tried editing to "lua\draw_hook_post = 'main main2'," but this didnt work. I then tried:
but this only launched main2.
The chatbot suggested:
then it instructed to put this in .lua
end
and this in the config file:
but this didnt work either. Then it had me edit the .lua bit to:
and this also failed to work, displaying NOTHING, not even the 2nd .lua
I am out of ideas for how to question the bot to get a correct answer. Can anyone here please show me how to launch two .lua functions with a single separate config file?
Thank you for reading,
Logan
https://redd.it/1ieocw8
@r_lua
Hello everyone,
I have been working for about an hour with chatgpt and it simple cannot do this.
I have a .lua file that contains two functions named main and main2
I have a config file for the linux app Conky that launches this .lua via the code:
`-- Lua Load`
`luaload = '/home/logansfury/.conky2/horiz.lua',
luadrawhookpost = 'main',`I tried editing to "lua\draw_hook_post = 'main main2'," but this didnt work. I then tried:
-- Lua Load lua_load = 'horiz2.lua wht_blue_cal.lua', lua_draw_hook_post = 'main', lua_draw_hook_post = 'main2',but this only launched main2.
The chatbot suggested:
lua_draw_hook_post = {'main', 'main2'},then it instructed to put this in .lua
function combined_hook()main()main2()end
and this in the config file:
lua_draw_hook_post = 'combined_hook',but this didnt work either. Then it had me edit the .lua bit to:
function combined_hook()if main then main() endif main2 then main2() endendand this also failed to work, displaying NOTHING, not even the 2nd .lua
I am out of ideas for how to question the bot to get a correct answer. Can anyone here please show me how to launch two .lua functions with a single separate config file?
Thank you for reading,
Logan
https://redd.it/1ieocw8
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Good Resources to Learn Lua. (This is for Beginners)
I was reading this post: https://www.reddit.com/r/lua/comments/1idin6j/ban\_posts\_asking\_for\_help\_to\_learn\_lua/
It seems that there are a lot of people asking the same "How to learn Lua?" question. I feel that there should just be one link we can just copy and paste for people that ask that question that way it is like an FAQ.
List resources that helped you or any good one that you know and upvote the ones that you like.
https://redd.it/1ieu5gq
@r_lua
I was reading this post: https://www.reddit.com/r/lua/comments/1idin6j/ban\_posts\_asking\_for\_help\_to\_learn\_lua/
It seems that there are a lot of people asking the same "How to learn Lua?" question. I feel that there should just be one link we can just copy and paste for people that ask that question that way it is like an FAQ.
List resources that helped you or any good one that you know and upvote the ones that you like.
https://redd.it/1ieu5gq
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lossless 60% compression in 1000 lines of C (with Lua bindings)
Hey everyone, I wrote a compression and binary diff algorithm that gets to qbout 40% lossless compression (zip is about 33% compression for comparison).
It's primary purpose is to implement patching for my own version control, the compression ability is gravy on top with minimal code.
It uses a variation of xdiff compression (I call rdiff) and then Huffman encoded. Check it out!
https://github.com/civboot/civlua/blob/main/lib/smol
https://lua.civboot.org#Package_smol
https://redd.it/1iex7bg
@r_lua
Hey everyone, I wrote a compression and binary diff algorithm that gets to qbout 40% lossless compression (zip is about 33% compression for comparison).
It's primary purpose is to implement patching for my own version control, the compression ability is gravy on top with minimal code.
It uses a variation of xdiff compression (I call rdiff) and then Huffman encoded. Check it out!
https://github.com/civboot/civlua/blob/main/lib/smol
https://lua.civboot.org#Package_smol
https://redd.it/1iex7bg
@r_lua
GitHub
civlua/lib/smol at main · civboot/civlua
self contained software to build a minimalist dev environment. - civboot/civlua
I've made MDN style Lua Documentation (LuaDocs)
Hi there!
Back in 2022, I was doing some game modding and found it very hard and slow to reference Lua for programming.
So I decided to create proper documentation following MDN sytle: The ones created from the manual itself, but in a modern format: https://www.luadocs.com/docs/introduction
I come from JavaScript, and I never had to learn Lua - I just knew it, but I always kept forgetting how to use stuff or what functions even existed.
The documentation isn't finished, but if anyone wants to help, or if there's interest I'll be up for finishing it off.
Got plenty of ideas, but want to see if anyones interested in this, if yes I'll continue it for the community and get it into a solid state but I want to see if it'll be of interest to anyone, as I no longer use Lua.
https://redd.it/1if0www
@r_lua
Hi there!
Back in 2022, I was doing some game modding and found it very hard and slow to reference Lua for programming.
So I decided to create proper documentation following MDN sytle: The ones created from the manual itself, but in a modern format: https://www.luadocs.com/docs/introduction
I come from JavaScript, and I never had to learn Lua - I just knew it, but I always kept forgetting how to use stuff or what functions even existed.
The documentation isn't finished, but if anyone wants to help, or if there's interest I'll be up for finishing it off.
Got plenty of ideas, but want to see if anyones interested in this, if yes I'll continue it for the community and get it into a solid state but I want to see if it'll be of interest to anyone, as I no longer use Lua.
https://redd.it/1if0www
@r_lua
typosafe and performant enum in 60 lines of code
[http://lua.civboot.org/#metaty.enum](http://lua.civboot.org/#metaty.enum)
[https://github.com/civboot/civlua/blob/main/lib/metaty/metaty.lua#L385](https://github.com/civboot/civlua/blob/main/lib/metaty/metaty.lua#L385)
Hey everyone, I created typosafe enums as part of my metatype module. The main advantages are:
* allows using either strings or ids (integers) as your enum "value" -- as long as your outer API converts to the one you expect using `myEnumName = MyEnum.name(myEnumNameOrId)`
* checks that your "matcher" table-of-functions handles all possible variants, throwing an error at module instantiation time if not (you should only define these tables in your module (i.e. not inside a function call) since creating the table is a bit expensive)
* Can be used in the proto-like serialization format I am writing (still WIP)
Note: I haven't pushed it to luarocks yet, but will soonish.
https://redd.it/1ifax1k
@r_lua
[http://lua.civboot.org/#metaty.enum](http://lua.civboot.org/#metaty.enum)
[https://github.com/civboot/civlua/blob/main/lib/metaty/metaty.lua#L385](https://github.com/civboot/civlua/blob/main/lib/metaty/metaty.lua#L385)
Hey everyone, I created typosafe enums as part of my metatype module. The main advantages are:
* allows using either strings or ids (integers) as your enum "value" -- as long as your outer API converts to the one you expect using `myEnumName = MyEnum.name(myEnumNameOrId)`
* checks that your "matcher" table-of-functions handles all possible variants, throwing an error at module instantiation time if not (you should only define these tables in your module (i.e. not inside a function call) since creating the table is a bit expensive)
* Can be used in the proto-like serialization format I am writing (still WIP)
Note: I haven't pushed it to luarocks yet, but will soonish.
https://redd.it/1ifax1k
@r_lua
How to display error messages nicely?
When using error(msg) the output seems too verbose if I simply want to provide the user with an error message:
local err_msg = string.format("%d %s: %s", status_code, response.error.type, response.error.message) error(err_msg)local err_msg = string.format("%d %s: %s", status_code, response.error.type, response.error.message)
error(err_msg)
However while using print(msg) followed by os.exit() achieves the desired effect it seems to hacky:
print(err_msg)
os.exit()
What is a common approach?
https://redd.it/1ifcm0t
@r_lua
When using error(msg) the output seems too verbose if I simply want to provide the user with an error message:
local err_msg = string.format("%d %s: %s", status_code, response.error.type, response.error.message) error(err_msg)local err_msg = string.format("%d %s: %s", status_code, response.error.type, response.error.message)
error(err_msg)
However while using print(msg) followed by os.exit() achieves the desired effect it seems to hacky:
print(err_msg)
os.exit()
What is a common approach?
https://redd.it/1ifcm0t
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Connecting to UNIX socket with luaposix
Hi all, I'm trying to figure out how to connect to a UNIX socket with luaposix. I've been looking through their API documentation and they have an example on how to connect to web sockets, but not this. It might be similar but I'm severely lacking on socket programming.
The reason I'm doing this is the Astal framework supports Lua, but it also has no native libraries for Sway as far as I know. So to get my workspaces and query other info about Sway, obviously I'd need to connect to the IPC.
local posix = require("posix.unistd")
local M = require("posix.sys.socket")
local sock_path = os.getenv("SWAYSOCK")
local r, err = M.getaddrinfo(sock_path, "unix", { family = M.AF_UNIX, socktype = M.SOCK_STREAM })
local sock, err = M.socket(M.AF_UNIX, M.SOCK_STREAM, 0)
if not sock then
print("Error creating socket: " .. err)
return
end
local result, err = M.connect(sock, r[1\])
if not result then
print("Error connecting to the socket: " .. err)
return
end
local command = '{"jsonrpc": "2.0", "id": 1, "method": "get_version"}'
local result, err = posix.write(sock, command)
if not result then
print("Error sending data to socket: " .. err)
return
end
local response = posix.read(sock, 1024)
if response then
print("Response from Sway IPC: " .. response)
else
print("Error reading from socket: " .. err)
end
posix.close(sock)
I don't have this in a code block because everytime I tried, reddit would mash it together onto one line.
https://redd.it/1ifq4lo
@r_lua
Hi all, I'm trying to figure out how to connect to a UNIX socket with luaposix. I've been looking through their API documentation and they have an example on how to connect to web sockets, but not this. It might be similar but I'm severely lacking on socket programming.
The reason I'm doing this is the Astal framework supports Lua, but it also has no native libraries for Sway as far as I know. So to get my workspaces and query other info about Sway, obviously I'd need to connect to the IPC.
local posix = require("posix.unistd")
local M = require("posix.sys.socket")
local sock_path = os.getenv("SWAYSOCK")
local r, err = M.getaddrinfo(sock_path, "unix", { family = M.AF_UNIX, socktype = M.SOCK_STREAM })
local sock, err = M.socket(M.AF_UNIX, M.SOCK_STREAM, 0)
if not sock then
print("Error creating socket: " .. err)
return
end
local result, err = M.connect(sock, r[1\])
if not result then
print("Error connecting to the socket: " .. err)
return
end
local command = '{"jsonrpc": "2.0", "id": 1, "method": "get_version"}'
local result, err = posix.write(sock, command)
if not result then
print("Error sending data to socket: " .. err)
return
end
local response = posix.read(sock, 1024)
if response then
print("Response from Sway IPC: " .. response)
else
print("Error reading from socket: " .. err)
end
posix.close(sock)
I don't have this in a code block because everytime I tried, reddit would mash it together onto one line.
https://redd.it/1ifq4lo
@r_lua
how can i choose a specific line of a txt file and give it to the variable named word
https://redd.it/1ig23gx
@r_lua
https://redd.it/1ig23gx
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Question about copying tables
This is not about how to do it, but rather if I am right about the cause of a bug.
I have a default table that I use, it is then copied over to new instances to allow them to handle the variables themselves.
local a = {b=1, c=2,d={e=1,f=10}}
When I copy them, I use the standard code,
function table.copy(t)
local t2 = {}
for k,v in pairs(t) do
t2k = v
end
for k,v in pairs(t.d)
t2.dk = v
end
return t2
end
However, when I made a change a t2.de, it would change it for all instances. When I fixed this, I basically reset d by doing d={} before it is copied on the guess that I am creating a reference to td when I was copying it?
Things are working, I just want to be certain I am not going to have a bug related to this down the road.
https://redd.it/1ig9pzb
@r_lua
This is not about how to do it, but rather if I am right about the cause of a bug.
I have a default table that I use, it is then copied over to new instances to allow them to handle the variables themselves.
local a = {b=1, c=2,d={e=1,f=10}}
When I copy them, I use the standard code,
function table.copy(t)
local t2 = {}
for k,v in pairs(t) do
t2k = v
end
for k,v in pairs(t.d)
t2.dk = v
end
return t2
end
However, when I made a change a t2.de, it would change it for all instances. When I fixed this, I basically reset d by doing d={} before it is copied on the guess that I am creating a reference to td when I was copying it?
Things are working, I just want to be certain I am not going to have a bug related to this down the road.
https://redd.it/1ig9pzb
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Any good game engines that use lua? (besides roblox)
I like lua and its concept but i cant really find many tools or engines that use lua, the only one i could find was roblox or some overprices junk but i havent look that hard.
What are some notable game engines that use lua that have a interface to work with?
or are there better ways to try out lua?
https://redd.it/1ig8e6g
@r_lua
I like lua and its concept but i cant really find many tools or engines that use lua, the only one i could find was roblox or some overprices junk but i havent look that hard.
What are some notable game engines that use lua that have a interface to work with?
or are there better ways to try out lua?
https://redd.it/1ig8e6g
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community