Regarding metatable definitions
Hey might be a stupid question but why does:
local v = {}
v.add = function(left, right)
return setmetatable({
left1 + right1,
left2 + right2,
left3 + right3
}, v)
end
local v1 = setmetatable({3, 1, 5}, v)
local v2 = setmetatable({-3, 2, 2}, v)
local v3 = v1 + v2
print(v31, v32, v33)
v3 = v3 + v3
print(v31, v32, v33)
work fine and returns value as expected:
0 3 7
0 6 14
but this does not:
local v = {
add = function(left, right)
return setmetatable({
left1 + right1,
left2 + right2,
left3 + right3
}, v)
end
}
local v1 = setmetatable({3, 1, 5}, v)
local v2 = setmetatable({-3, 2, 2}, v)
local v3 = v1 + v2
print(v31, v32, v33)
v3 = v3 + v3
print(v31, v32, v33)
Got error in output:
0 3 7
lua: hello.lua:16: attempt to perform arithmetic on a table value (local 'v3')
stack traceback:
hello.lua:16: in main chunk
C: in ?
I did ask both chatgpt and grok but couldn't understand either of their reasonings. Was trying to learn lua through: https://www.youtube.com/watch?v=CuWfgiwI73Q/
https://redd.it/1jn7blm
@r_lua
Hey might be a stupid question but why does:
local v = {}
v.add = function(left, right)
return setmetatable({
left1 + right1,
left2 + right2,
left3 + right3
}, v)
end
local v1 = setmetatable({3, 1, 5}, v)
local v2 = setmetatable({-3, 2, 2}, v)
local v3 = v1 + v2
print(v31, v32, v33)
v3 = v3 + v3
print(v31, v32, v33)
work fine and returns value as expected:
0 3 7
0 6 14
but this does not:
local v = {
add = function(left, right)
return setmetatable({
left1 + right1,
left2 + right2,
left3 + right3
}, v)
end
}
local v1 = setmetatable({3, 1, 5}, v)
local v2 = setmetatable({-3, 2, 2}, v)
local v3 = v1 + v2
print(v31, v32, v33)
v3 = v3 + v3
print(v31, v32, v33)
Got error in output:
0 3 7
lua: hello.lua:16: attempt to perform arithmetic on a table value (local 'v3')
stack traceback:
hello.lua:16: in main chunk
C: in ?
I did ask both chatgpt and grok but couldn't understand either of their reasonings. Was trying to learn lua through: https://www.youtube.com/watch?v=CuWfgiwI73Q/
https://redd.it/1jn7blm
@r_lua
YouTube
Everything You Need To Start Writing Lua
Ok, so maybe not exactly 1000 seconds, but Fireship doesn't stick to exactly 100 seconds either!!
I mentioned my course from boot dev, which you can check out here: https://boot.dev/teej
All notes are here: https://github.com/tjdevries/advent-of-nvim/b…
I mentioned my course from boot dev, which you can check out here: https://boot.dev/teej
All notes are here: https://github.com/tjdevries/advent-of-nvim/b…
Sony Inzone interfering with Lua noscript
I’m not quite sure if this is the right place for this but I use lua noscripts on my Logitech mouse for video games, and today I bought some Sony Inzone earbuds. It seems to make the values for the recoil higher out of nowhere but it’s only while the usb-c dongle is plugged in. It doesn’t change the actual values in the noscript but it responds about 2-3x stronger. It seems unrelated to the control center app from Sony but is affected by the dongle. Does anyone have a fix for this or know why this is happening?
https://redd.it/1jnstfp
@r_lua
I’m not quite sure if this is the right place for this but I use lua noscripts on my Logitech mouse for video games, and today I bought some Sony Inzone earbuds. It seems to make the values for the recoil higher out of nowhere but it’s only while the usb-c dongle is plugged in. It doesn’t change the actual values in the noscript but it responds about 2-3x stronger. It seems unrelated to the control center app from Sony but is affected by the dongle. Does anyone have a fix for this or know why this is happening?
https://redd.it/1jnstfp
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
A good learning resource for lua and programming in general?
What are your recommendations?
https://redd.it/1jntn67
@r_lua
What are your recommendations?
https://redd.it/1jntn67
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
How to interpret
Here is my snippet code as follows:d
#!/usr/bin/env resty
local ffi = require("ffi")
local bit = require "bit"
local lshift = bit.lshift
local function printx(x)
print("0x"..bit.tohex(x))
end
local lshiftuint64
do
local ffiuint = ffi.new("uint64t")
lshiftuint64 = function(v, offset)
ffiuint = v
return lshift(ffiuint, offset)
end
end
print("--- ffiuint = v ---")
printx(lshiftuint64(2, 61))
printx(lshiftuint64(2ULL, 61))
printx(lshiftuint64(0x2ULL, 61))
local lshiftuint64new
do
lshiftuint64new = function(v, offset)
local ffiuint = ffi.new("uint64t", v)
return lshift(ffiuint, offset)
end
end
print("--- ffiuint = ffi.new ---")
printx(lshiftuint64new(2, 61))
printx(lshiftuint64new(2ULL, 61))
printx(lshiftuint64new(0x2ULL, 61))
The output on my macOS is:
--- ffiuint = v ---
0x40000000
0x4000000000000000
0x4000000000000000
--- ffiuint = ffi.new ---
0x4000000000000000
0x4000000000000000
0x4000000000000000
The output of
https://redd.it/1jntw7g
@r_lua
bit.lshift 2 and bit.lshift 2ULL?Here is my snippet code as follows:d
#!/usr/bin/env resty
local ffi = require("ffi")
local bit = require "bit"
local lshift = bit.lshift
local function printx(x)
print("0x"..bit.tohex(x))
end
local lshiftuint64
do
local ffiuint = ffi.new("uint64t")
lshiftuint64 = function(v, offset)
ffiuint = v
return lshift(ffiuint, offset)
end
end
print("--- ffiuint = v ---")
printx(lshiftuint64(2, 61))
printx(lshiftuint64(2ULL, 61))
printx(lshiftuint64(0x2ULL, 61))
local lshiftuint64new
do
lshiftuint64new = function(v, offset)
local ffiuint = ffi.new("uint64t", v)
return lshift(ffiuint, offset)
end
end
print("--- ffiuint = ffi.new ---")
printx(lshiftuint64new(2, 61))
printx(lshiftuint64new(2ULL, 61))
printx(lshiftuint64new(0x2ULL, 61))
The output on my macOS is:
--- ffiuint = v ---
0x40000000
0x4000000000000000
0x4000000000000000
--- ffiuint = ffi.new ---
0x4000000000000000
0x4000000000000000
0x4000000000000000
The output of
printx(lshift_uint64(2, 61)) seems just 32-bit long?https://redd.it/1jntw7g
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
ide's or libraries for young learners?
i have a pre-teen sibling who wants to learn coding, he has tried scratch so he has somewhat of an experience to coding, he has created some games with it and he did it well! he told me he wanted to try 'real' code, so this is where this reddit post steps in.
he loves to try new things, so he doesn't mind doing pure code!
https://redd.it/1jo0p5s
@r_lua
i have a pre-teen sibling who wants to learn coding, he has tried scratch so he has somewhat of an experience to coding, he has created some games with it and he did it well! he told me he wanted to try 'real' code, so this is where this reddit post steps in.
he loves to try new things, so he doesn't mind doing pure code!
https://redd.it/1jo0p5s
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Using continuation functions as normal functions possible?
I have often the case where I want to loop and within that loop call a lua function or have to yield, but yieldable with continuation.
For that I have to provide a continuation function which only functions as trampoline to call the normal function again.
int foo(luaState*);
int foocontinue(luaState* L, int, luaKContext) {
foo(L);
}
int foo(luaState* L) {
while (true) {
/* do things */
luayield(L, 0, NULL, &foocontinue);
}
}
int main() {
// ...
luapushcfunction(L, &foo);
// ...
}
Because I have to persist the runtime, I'm using Eris, I now also have to add the continuation function to the persistency table.
I would love to remove that boilerplate by simply doing something like this:
int foo(luaState* L, int, luaKContext) {
while (true) {
/ do things /
luayield(L, 0, NULL, &foo);
}
}
int main() {
// ...
luapushcfunction(L, &foo);
// ...
}
Using reinterpret cast that seems to work just fine but idk if that is really stable and doesnt cause undefined behaviour.
So, is this allowed or not?
https://redd.it/1jo284c
@r_lua
I have often the case where I want to loop and within that loop call a lua function or have to yield, but yieldable with continuation.
For that I have to provide a continuation function which only functions as trampoline to call the normal function again.
int foo(luaState*);
int foocontinue(luaState* L, int, luaKContext) {
foo(L);
}
int foo(luaState* L) {
while (true) {
/* do things */
luayield(L, 0, NULL, &foocontinue);
}
}
int main() {
// ...
luapushcfunction(L, &foo);
// ...
}
Because I have to persist the runtime, I'm using Eris, I now also have to add the continuation function to the persistency table.
I would love to remove that boilerplate by simply doing something like this:
int foo(luaState* L, int, luaKContext) {
while (true) {
/ do things /
luayield(L, 0, NULL, &foo);
}
}
int main() {
// ...
luapushcfunction(L, &foo);
// ...
}
Using reinterpret cast that seems to work just fine but idk if that is really stable and doesnt cause undefined behaviour.
So, is this allowed or not?
https://redd.it/1jo284c
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Good resources on Lua that also teach programming fundamentals?
I'd like to believe I know Lua well enough, having used it a lot for game modding. However there's a lot of people who come to our community trying to make mods with zero knowledge of programming, and trying to help those people gets frustrating for everyone involved.
What resources are there that teach Lua while also explaining basic concepts (variables, conditionals, loops, etc.)? First few tutorials I could find seem to be made for people who already know programming and just need a crash course on specifics of the language...
https://redd.it/1jo4ihc
@r_lua
I'd like to believe I know Lua well enough, having used it a lot for game modding. However there's a lot of people who come to our community trying to make mods with zero knowledge of programming, and trying to help those people gets frustrating for everyone involved.
What resources are there that teach Lua while also explaining basic concepts (variables, conditionals, loops, etc.)? First few tutorials I could find seem to be made for people who already know programming and just need a crash course on specifics of the language...
https://redd.it/1jo4ihc
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Termfx make fails with error lua.h: No such file or directory
What it says on the tincan. Attempting to build Termfx without Luarocks (because luarocks has caused nothing but pain and suffering for me) and I'm not able to make it successfully as it doesn't seem to be able to find the C headers.
I think this boils down to me not specifying where the lua.h file is, but I don't know how I can do that. Thanks for any help
https://redd.it/1jo7trj
@r_lua
What it says on the tincan. Attempting to build Termfx without Luarocks (because luarocks has caused nothing but pain and suffering for me) and I'm not able to make it successfully as it doesn't seem to be able to find the C headers.
I think this boils down to me not specifying where the lua.h file is, but I don't know how I can do that. Thanks for any help
https://redd.it/1jo7trj
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lua + JUCE Audio framework - the adventure begins! A simple integration of Lua into one of the best C++ frameworks for doing Audio-related work.
https://github.com/seclorum/LuaParamaBangPlugin
https://redd.it/1jormfh
@r_lua
https://github.com/seclorum/LuaParamaBangPlugin
https://redd.it/1jormfh
@r_lua
GitHub
GitHub - seclorum/LuaParamaBangPlugin: A simple example of integrating Lua in a JUCE plugin such that Lua code can be run on paramChange…
A simple example of integrating Lua in a JUCE plugin such that Lua code can be run on paramChange and processBlock updates. - seclorum/LuaParamaBangPlugin
Accidently deleted Ghub lua noscript command and now cant remember.
There was a lua file located on my computer on D: , a noscript was running it without copying everything to GHUB,it was someting like D: ..... Test.lua, i accidently deleted it and cant remember now would you guys help me?
https://redd.it/1jp2z0m
@r_lua
There was a lua file located on my computer on D: , a noscript was running it without copying everything to GHUB,it was someting like D: ..... Test.lua, i accidently deleted it and cant remember now would you guys help me?
https://redd.it/1jp2z0m
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
ECS vs OOP in Roblox Development
https://open.substack.com/pub/ignaziop/p/ecs-vs-oop-in-roblox-development?utm_source=share&utm_medium=android&r=200s61
https://redd.it/1jp5ohd
@r_lua
https://open.substack.com/pub/ignaziop/p/ecs-vs-oop-in-roblox-development?utm_source=share&utm_medium=android&r=200s61
https://redd.it/1jp5ohd
@r_lua
Substack
ECS vs OOP in Roblox Development
When building games in Roblox, two common architectural approaches are Entity Component System (ECS) and Object-Oriented Programming (OOP).
Obfuscated lua file
Hey. I have a lua file that is in my fivem server, I need to edit a few things in the file
Is there a way to deobfuscate the file through my server key?
I bought the file legally
https://redd.it/1jp8yq8
@r_lua
Hey. I have a lua file that is in my fivem server, I need to edit a few things in the file
Is there a way to deobfuscate the file through my server key?
I bought the file legally
https://redd.it/1jp8yq8
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
What special Lua tutorial would be useful?
Hello I make YouTube tutorials. I made a general “Learn Lua” tutorial but I would like to make specific tutorials. I was thinking of teach concepts like strings (and its functions) and metatables. Are there any tutorials that would be useful please let me know?
https://redd.it/1jq4kyd
@r_lua
Hello I make YouTube tutorials. I made a general “Learn Lua” tutorial but I would like to make specific tutorials. I was thinking of teach concepts like strings (and its functions) and metatables. Are there any tutorials that would be useful please let me know?
https://redd.it/1jq4kyd
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
RE Clone?
So I would like to make what is essentially a classic RE Clone, survival horror genre, tank controls, fixed camera angles, pre rendered backgrounds, etc. Would Lua be a good platform for that?
https://redd.it/1jquivi
@r_lua
So I would like to make what is essentially a classic RE Clone, survival horror genre, tank controls, fixed camera angles, pre rendered backgrounds, etc. Would Lua be a good platform for that?
https://redd.it/1jquivi
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
funcional microphone help
Hi, I need help making or finding a code to make a functional microphone for voice chat in Roblox. If anyone has a noscript that might work, please share it with me and if you can, explain to me how to use it, hehe (sorry if I asked for too much).
https://redd.it/1jqvlcq
@r_lua
Hi, I need help making or finding a code to make a functional microphone for voice chat in Roblox. If anyone has a noscript that might work, please share it with me and if you can, explain to me how to use it, hehe (sorry if I asked for too much).
https://redd.it/1jqvlcq
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
What’s the best way to learn lua?
I’m brand new to lua and I’ve wanted to learn for years now specifically to noscript roblox games but also just to use for my own fun. Which was making me want to ask what applications, websites, videos are useful that could be recommended for me to learn?
https://redd.it/1jqvcl5
@r_lua
I’m brand new to lua and I’ve wanted to learn for years now specifically to noscript roblox games but also just to use for my own fun. Which was making me want to ask what applications, websites, videos are useful that could be recommended for me to learn?
https://redd.it/1jqvcl5
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Help me with noscript for GHub.
Hello, im just trying to make noscript that clicks certain points on the screen. Problem is, running noscript doesn't use right mouse button or doesnt use it at all. Also i need to run it, untill certain button is pressed. could you help me with that?
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 3 then
if IsKeyLockOn("capslock") then
repeat
MoveMouseTo(39785,17614)
PressMouseButton(2)
Sleep(10)
ReleaseMouseButton(2)
Sleep(2000)
MoveMouseTo(37258, 17492)
PressMouseButton(2)
Sleep(5)
ReleaseMouseButton(2)
Sleep(1000)
MoveMouseTo(28072, 34741)
PressMouseButton(2)
Sleep(10)
ReleaseMouseButton(2)
Sleep(1000)
MoveMouseTo(28550, 41665)
PressMouseButton(2)
Sleep(10)
ReleaseMouseButton(2)
Sleep(1000)
if not IsMouseButtonPressed(4) then break end
MoveMouseRelative(0,4)
Sleep(10)
PressMouseButton(2)
until not IsMouseButtonPressed(4) -- 4 = "Back"
end
end
end
https://redd.it/1jrjhqp
@r_lua
Hello, im just trying to make noscript that clicks certain points on the screen. Problem is, running noscript doesn't use right mouse button or doesnt use it at all. Also i need to run it, untill certain button is pressed. could you help me with that?
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 3 then
if IsKeyLockOn("capslock") then
repeat
MoveMouseTo(39785,17614)
PressMouseButton(2)
Sleep(10)
ReleaseMouseButton(2)
Sleep(2000)
MoveMouseTo(37258, 17492)
PressMouseButton(2)
Sleep(5)
ReleaseMouseButton(2)
Sleep(1000)
MoveMouseTo(28072, 34741)
PressMouseButton(2)
Sleep(10)
ReleaseMouseButton(2)
Sleep(1000)
MoveMouseTo(28550, 41665)
PressMouseButton(2)
Sleep(10)
ReleaseMouseButton(2)
Sleep(1000)
if not IsMouseButtonPressed(4) then break end
MoveMouseRelative(0,4)
Sleep(10)
PressMouseButton(2)
until not IsMouseButtonPressed(4) -- 4 = "Back"
end
end
end
https://redd.it/1jrjhqp
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Luarocks Error: Attempted to index a nil value (field 'LUA_BINDIR')
Whenever I try to do anything with luarocks (ANYTHING) I get a litle pop up with this error:
\[string "src/luarocks/core/cfg.lua"\]:824: attempt to index a nil value (field 'LUA BINDIR')
stack traceback:
\[string "src/luarocks/core/cfg.lua"\]:824: in function 'luarocks.core.cfg.init
\[string "src/luarocks/loader.lua"\]:21: in main chunk \[C\]: in function 'require'
\[string "luarocks"\]:5: in main chunk \[C\]: in ?
I have LuaJIT installed as well as LOVE, which I am trying to get luarocks to work with. I have my paths correctly added, and everything SHOULD work, but it doesn't. I cant do any cmd commands with luarocks because everything returns the same error. I can't find anything online.
(Edit: When I say I was trying to use LOVE with luarocks, I'm not trying to install LOVE, I'm trying to install packages so I can used them WITH love, just FYI.)
https://redd.it/1jrv0tp
@r_lua
Whenever I try to do anything with luarocks (ANYTHING) I get a litle pop up with this error:
\[string "src/luarocks/core/cfg.lua"\]:824: attempt to index a nil value (field 'LUA BINDIR')
stack traceback:
\[string "src/luarocks/core/cfg.lua"\]:824: in function 'luarocks.core.cfg.init
\[string "src/luarocks/loader.lua"\]:21: in main chunk \[C\]: in function 'require'
\[string "luarocks"\]:5: in main chunk \[C\]: in ?
I have LuaJIT installed as well as LOVE, which I am trying to get luarocks to work with. I have my paths correctly added, and everything SHOULD work, but it doesn't. I cant do any cmd commands with luarocks because everything returns the same error. I can't find anything online.
(Edit: When I say I was trying to use LOVE with luarocks, I'm not trying to install LOVE, I'm trying to install packages so I can used them WITH love, just FYI.)
https://redd.it/1jrv0tp
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Help im making a battlegrounds game and do understand these errors!
https://preview.redd.it/o5mpi2kuq0te1.png?width=1897&format=png&auto=webp&s=8a770d6acf66973a307994e0caf8b6afcbaad268
https://preview.redd.it/m91ux2kuq0te1.png?width=1906&format=png&auto=webp&s=0bee4330aea0c39c2123f3b418c2691189110af4
https://preview.redd.it/7nnfs2kuq0te1.png?width=1249&format=png&auto=webp&s=a31d91b24d11af52395afc7619ec8967a3ea8adb
https://preview.redd.it/7g8g94kuq0te1.png?width=1907&format=png&auto=webp&s=b17fcb8498fd8c065780d1df1b63b01d0b84edb6
please if anyone knows these tell me
https://redd.it/1js3jhn
@r_lua
https://preview.redd.it/o5mpi2kuq0te1.png?width=1897&format=png&auto=webp&s=8a770d6acf66973a307994e0caf8b6afcbaad268
https://preview.redd.it/m91ux2kuq0te1.png?width=1906&format=png&auto=webp&s=0bee4330aea0c39c2123f3b418c2691189110af4
https://preview.redd.it/7nnfs2kuq0te1.png?width=1249&format=png&auto=webp&s=a31d91b24d11af52395afc7619ec8967a3ea8adb
https://preview.redd.it/7g8g94kuq0te1.png?width=1907&format=png&auto=webp&s=b17fcb8498fd8c065780d1df1b63b01d0b84edb6
please if anyone knows these tell me
https://redd.it/1js3jhn
@r_lua