I want to learn how to code with Lua - how do I start? where do I start?
For those who have experience with Lua, how did you start? where did you start?
All I know of Lua is that it is considered "simple" and that it is used for games - I really would like to somewhat grasp Lua so I can start considering making games myself.
https://redd.it/1k4ktdk
@r_lua
For those who have experience with Lua, how did you start? where did you start?
All I know of Lua is that it is considered "simple" and that it is used for games - I really would like to somewhat grasp Lua so I can start considering making games myself.
https://redd.it/1k4ktdk
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Do I need require for each TU?
I'm not super familiar with LUA. I have an entry point of so called main noscript -
https://redd.it/1k4lisq
@r_lua
I'm not super familiar with LUA. I have an entry point of so called main noscript -
entry.lua, I have a Logger.lua that has the tools for exactly what it says. Main noscripts has access to logger via require. Now I have to use logging tools in Events.lua - do I also need a require or because Events.lua is already "included" in main noscript the logging definitions are exposed higher up the chain and I can use them? And if I dont - any potentials side-effects form including them via require to appease luals?https://redd.it/1k4lisq
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
A simple noscript to generate html code.
I just wanted to share this code to generate html code from lua, i made this because i don't like writing html and for fun to do something in lua. Any sugestions to improve it?
https://gitlab.com/-/snippets/4836971
https://redd.it/1k5qng1
@r_lua
I just wanted to share this code to generate html code from lua, i made this because i don't like writing html and for fun to do something in lua. Any sugestions to improve it?
https://gitlab.com/-/snippets/4836971
https://redd.it/1k5qng1
@r_lua
GitLab
Generate html code from lua ($4836971) · Snippets · GitLab
Differences between Lua and LuaJIT?
Hi all. I've been a casual user of Lua for years and of LuaJIT for just a few months. I am not clear on all of the differences I need to know when writing code.
I know that integer division (//) is not implemented in LuaJIT and that LuaJIT has increased interoperability with C (which I haven't yet used). Yesterday I wrote a bit of code for LuaJIT that produces differently formatted output between Lua (5.4) and LuaJIT (5.1).
It worries me that there might be more gotchas lurking and a cheat sheet of everything a Lua programmer should know when switching to LuaJIT would be really useful (before I start diving into Lua version changes and seeing of this is a Lua version difference and not a Lua/LuaJIT difference).
Can anyone help?
https://redd.it/1k60myn
@r_lua
Hi all. I've been a casual user of Lua for years and of LuaJIT for just a few months. I am not clear on all of the differences I need to know when writing code.
I know that integer division (//) is not implemented in LuaJIT and that LuaJIT has increased interoperability with C (which I haven't yet used). Yesterday I wrote a bit of code for LuaJIT that produces differently formatted output between Lua (5.4) and LuaJIT (5.1).
It worries me that there might be more gotchas lurking and a cheat sheet of everything a Lua programmer should know when switching to LuaJIT would be really useful (before I start diving into Lua version changes and seeing of this is a Lua version difference and not a Lua/LuaJIT difference).
Can anyone help?
https://redd.it/1k60myn
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
simulate MicroLua on Mac?
Hi all,
I'm trying to make a DS game to be run via MicroLua DS on DSi. I'm using a 2020 MacBook Pro M1 computer.
To test my program, I first tried using MicroLua Simulator https://sourceforge.net/p/microlua/wiki/MicroLuaSimulator/ but I couldn't compile it.
Then I tried Desmume, using the instructions given here: https://sourceforge.net/p/microlua/wiki/DeSmuME/ but the gba slot it mentions was nowhere to be found.
what do?
https://redd.it/1k69cww
@r_lua
Hi all,
I'm trying to make a DS game to be run via MicroLua DS on DSi. I'm using a 2020 MacBook Pro M1 computer.
To test my program, I first tried using MicroLua Simulator https://sourceforge.net/p/microlua/wiki/MicroLuaSimulator/ but I couldn't compile it.
Then I tried Desmume, using the instructions given here: https://sourceforge.net/p/microlua/wiki/DeSmuME/ but the gba slot it mentions was nowhere to be found.
what do?
https://redd.it/1k69cww
@r_lua
is there a way i can make my noscript smaller?
i'm new to lua i just made a rock paper scissors game but i want to make the noscript smaller is there a way i can do that?
https://redd.it/1k83lvu
@r_lua
i'm new to lua i just made a rock paper scissors game but i want to make the noscript smaller is there a way i can do that?
math.randomseed(os.time())table = {"rock", "paper", "scissors"}number = math.random(1, 3)print ("Welcome to Rock Paper Scissors!\nChoose Your Move!")move = string.lower(io.read("*l"))if move == "rock" thenif number == 1 thenprint("Tie!")elseif number == 2 thenprint ("You Lose!")else print ("You Win!") endendif move == "paper" thenif number == 1 thenprint("You Win!")elseif number == 2 thenprint ("Tie!")else print ("You Lose!") endendif move == "scissors" thenif number == 1 thenprint("You Lose!")elseif number == 2 thenprint ("You Win!")else print ("You Lose!") endendprint (table[number])https://redd.it/1k83lvu
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
working on a laser targeting system. i am using a public lua radar that has the option to mark as a friendly(iff) or a target (lok) and i added a laser locking mode. it works except that it marks them as friendly's not target's. for stormworks
T={}F={}MT=10;MD=200;pi2=math.pi*2;p4=pi2/4;m=0;w,h=0,0;c=math.cos;r=table.remove;s=math.sin;srt=math.sqrt;tria=screen.drawTriangleF;sdc=screen.drawCircle;ot=output.setNumber;ip=input.getNumber;stc=screen.setColor;dL=screen.drawLine;function clr()for a,b in pairs(T)do b.lok=false end end;sb=output.setBool;function onTick()u,l=0,0;isP=input.getBool(2)tx=ip(23)ty=ip(24)cm=math.fmod((ip(22)+1.25)*pi2,pi2)Gx=ip(25)Gy=ip(26)rg=ip(28)alt=ip(29)ro=ip(30)*pi2;ptc=ip(31)*pi2;n=4;while n<12 do fx=ip(n)fy=ip(n+1)fz=ip(n+2)table.insert(F,{x=fx,y=fy,z=fz})n=n+3 end;if isP then t=idx(T,tx,ty)if t\~=nil then clr()sb(2,true)T[t\].lok=true else clr()sb(2,false)end end
\------------ laser mode start
select_x = input.getNumber(7)
select_y = input.getNumber(8)
if select_x \~= 0 and select_y \~= 0 then
local foundTarget = idx(T, select_x, select_y)
if foundTarget \~= nil then
clr()
T[foundTarget\].lok = true
sb(2, true)
end
end
\---------------laser mode end
;tg={tgt=input.getBool(1),d=ip(1),az=ip(2)*pi2,el=ip(3)*pi2,ttl=100,hd=0,spd=1,spdx=1,spdy=1,spdz=1,ti=m,br=0,lok=false,iff=false}h_dst=tg.d*c(tg.el)tg.tgx,tg.tgy,tg.tgz=cpT(Gx,Gy,alt,tg,ro,ptc,cm)if tg.tgt and h_dst>30 and h_dst<rg then e_t=nil;nrdst=math.huge;ni=nil;for e,f in ipairs(T)do px,py=nil,nil;dlt=(tg.ti-f.ti)/60;dist=srt((f.tgx-tg.tgx)\^2+(f.tgy-tg.tgy)\^2+(f.tgz-tg.tgz)\^2)if f.spd>50 then px=f.tgx+f.spdx*dlt;py=f.tgy+f.spdy*dlt;pz=f.tgz+f.spdz*dlt end;if px==nil or py==nil then if dist<=MD and dist<nrdst then nrdst=dist;e_t=f;ni=e end else sph=srt((tg.tgx-px)\^2+(tg.tgx-py)\^2+(tg.tgx-pz)\^2)if sph<=MD or dist<MD then e_t=f;ni=e end end end;if e_t then rz=tg.d/rg;tg.x=w/2+rz*w*2*math.cos(tg.az-p4)tg.y=h+rz*h*2*math.sin(tg.az-p4)dq=srt((tg.tgx-e_t.tgx)\^2+(tg.tgy-e_t.tgy)\^2+(tg.tgz-e_t.tgz)\^2)dlt=(tg.ti-e_t.ti)/60;spdx=(e_t.tgx-tg.tgx)/dlt;spdy=(e_t.tgy-tg.tgy)/dlt;spdz=(e_t.tgz-tg.tgz)/dlt;spd=srt(spdx\^2+spdy\^2)e_t.d=tg.d;e_t.az=tg.az;e_t.el=tg.el;e_t.x=tg.x;e_t.y=tg.y;e_t.ttl=100;e_t.iff=tg.iff;if dq>20 and math.abs(spd-e_t.spd)<200 then e_t.tgz=tg.tgz;e_t.tgy=tg.tgy;e_t.tgx=tg.tgx;e_t.spd=spd;e_t.spdx=spdx;e_t.spdy=spdy;e_t.spdz=spdz;hdg=cdH(e_t,tg)e_t.hd=hdg end;e_t.ti=tg.ti else if ni then r(T,ni)end;tg.id=#T+1;table.insert(T,tg)end end;if#T>MT then r(T,1)end;for a,tg in pairs(T)do for a,n in ipairs(F)do d=srt((tg.tgx-n.x)\^2+(tg.tgy-n.y)\^2+(tg.tgz-n.z)\^2)if d<50 then tg.iff=true end end;r_=tg.d/rg;h_dst=tg.d*c(tg.el)tg.x=w/2+r_*w*2*c(tg.az-p4)tg.y=h+r_*h*2*s(tg.az-p4)tg.ttl=tg.ttl-1;if tg.ttl<=0 then r(T,a)end;if h_dst>rg then r(T,a)end;if tg.lok then ot(7,tg.spd)ot(8,math.deg(tg.hd))ot(1,tg.tgx)ot(2,tg.tgy)ot(3,tg.tgz)ot(10,tg.az)ot(11,tg.el)end end;ot(5,#T)m=m+1 end;function onDraw()w=screen.getWidth()h=screen.getHeight()stc(0,255,0,255)for i,b in pairs(T)do dh(b,i)end end;function dh(tg,i)xd,xy=tg.x,tg.y;o=tg.hd;if tg.iff then stc(0,255,255,tg.ttl+150)else stc(0,255,0,tg.ttl+150)end;g=2;if tg.tgz>200 then g=3 elseif tg.tgz>400 then g=5 end;x1,y1=xd+g*c(o),xy+g*s(o)o=o+2*math.pi/3;x2,y2=xd+g*c(o),xy+g*s(o)o=o+2*math.pi/3;x3,y3=xd+g*c(o),xy+g*s(o)if tg.tgz<50 then if tg.lok then stc(255,150,0)screen.drawText(xd-4,xy,"[+\]")else screen.drawText(xd,xy,"+")end else if tg.lok then stc(255,150,0)tria(x1,y1,x2,y2,x3,y3)else screen.drawTriangle(x1,y1,x2,y2,x3,y3)end;dL(x1,y1,x1+4*s(tg.hd+p4),y1-4*c(tg.hd+p4))end end;function cdH(o,n)hd=cm-math.atan(n.spdy-o.spdy,n.spdx-o.spdx)-p4;return hd end;function idx(j,k,p)for e,b in pairs(j)do if k<=b.x+2 and k>=b.x-2 and p<=b.y+2 and p>=b.y-2 then return e end end;return nil end;function idM()return{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}end;function mxM(j,q)ra=idM()for e=1,4 do for v=1,4 do sum=0;for i=1,4 do sum=sum+j[e\][i\]*q[i\][v\]end;ra[e\][v\]=sum end end;return ra end;function
T={}F={}MT=10;MD=200;pi2=math.pi*2;p4=pi2/4;m=0;w,h=0,0;c=math.cos;r=table.remove;s=math.sin;srt=math.sqrt;tria=screen.drawTriangleF;sdc=screen.drawCircle;ot=output.setNumber;ip=input.getNumber;stc=screen.setColor;dL=screen.drawLine;function clr()for a,b in pairs(T)do b.lok=false end end;sb=output.setBool;function onTick()u,l=0,0;isP=input.getBool(2)tx=ip(23)ty=ip(24)cm=math.fmod((ip(22)+1.25)*pi2,pi2)Gx=ip(25)Gy=ip(26)rg=ip(28)alt=ip(29)ro=ip(30)*pi2;ptc=ip(31)*pi2;n=4;while n<12 do fx=ip(n)fy=ip(n+1)fz=ip(n+2)table.insert(F,{x=fx,y=fy,z=fz})n=n+3 end;if isP then t=idx(T,tx,ty)if t\~=nil then clr()sb(2,true)T[t\].lok=true else clr()sb(2,false)end end
\------------ laser mode start
select_x = input.getNumber(7)
select_y = input.getNumber(8)
if select_x \~= 0 and select_y \~= 0 then
local foundTarget = idx(T, select_x, select_y)
if foundTarget \~= nil then
clr()
T[foundTarget\].lok = true
sb(2, true)
end
end
\---------------laser mode end
;tg={tgt=input.getBool(1),d=ip(1),az=ip(2)*pi2,el=ip(3)*pi2,ttl=100,hd=0,spd=1,spdx=1,spdy=1,spdz=1,ti=m,br=0,lok=false,iff=false}h_dst=tg.d*c(tg.el)tg.tgx,tg.tgy,tg.tgz=cpT(Gx,Gy,alt,tg,ro,ptc,cm)if tg.tgt and h_dst>30 and h_dst<rg then e_t=nil;nrdst=math.huge;ni=nil;for e,f in ipairs(T)do px,py=nil,nil;dlt=(tg.ti-f.ti)/60;dist=srt((f.tgx-tg.tgx)\^2+(f.tgy-tg.tgy)\^2+(f.tgz-tg.tgz)\^2)if f.spd>50 then px=f.tgx+f.spdx*dlt;py=f.tgy+f.spdy*dlt;pz=f.tgz+f.spdz*dlt end;if px==nil or py==nil then if dist<=MD and dist<nrdst then nrdst=dist;e_t=f;ni=e end else sph=srt((tg.tgx-px)\^2+(tg.tgx-py)\^2+(tg.tgx-pz)\^2)if sph<=MD or dist<MD then e_t=f;ni=e end end end;if e_t then rz=tg.d/rg;tg.x=w/2+rz*w*2*math.cos(tg.az-p4)tg.y=h+rz*h*2*math.sin(tg.az-p4)dq=srt((tg.tgx-e_t.tgx)\^2+(tg.tgy-e_t.tgy)\^2+(tg.tgz-e_t.tgz)\^2)dlt=(tg.ti-e_t.ti)/60;spdx=(e_t.tgx-tg.tgx)/dlt;spdy=(e_t.tgy-tg.tgy)/dlt;spdz=(e_t.tgz-tg.tgz)/dlt;spd=srt(spdx\^2+spdy\^2)e_t.d=tg.d;e_t.az=tg.az;e_t.el=tg.el;e_t.x=tg.x;e_t.y=tg.y;e_t.ttl=100;e_t.iff=tg.iff;if dq>20 and math.abs(spd-e_t.spd)<200 then e_t.tgz=tg.tgz;e_t.tgy=tg.tgy;e_t.tgx=tg.tgx;e_t.spd=spd;e_t.spdx=spdx;e_t.spdy=spdy;e_t.spdz=spdz;hdg=cdH(e_t,tg)e_t.hd=hdg end;e_t.ti=tg.ti else if ni then r(T,ni)end;tg.id=#T+1;table.insert(T,tg)end end;if#T>MT then r(T,1)end;for a,tg in pairs(T)do for a,n in ipairs(F)do d=srt((tg.tgx-n.x)\^2+(tg.tgy-n.y)\^2+(tg.tgz-n.z)\^2)if d<50 then tg.iff=true end end;r_=tg.d/rg;h_dst=tg.d*c(tg.el)tg.x=w/2+r_*w*2*c(tg.az-p4)tg.y=h+r_*h*2*s(tg.az-p4)tg.ttl=tg.ttl-1;if tg.ttl<=0 then r(T,a)end;if h_dst>rg then r(T,a)end;if tg.lok then ot(7,tg.spd)ot(8,math.deg(tg.hd))ot(1,tg.tgx)ot(2,tg.tgy)ot(3,tg.tgz)ot(10,tg.az)ot(11,tg.el)end end;ot(5,#T)m=m+1 end;function onDraw()w=screen.getWidth()h=screen.getHeight()stc(0,255,0,255)for i,b in pairs(T)do dh(b,i)end end;function dh(tg,i)xd,xy=tg.x,tg.y;o=tg.hd;if tg.iff then stc(0,255,255,tg.ttl+150)else stc(0,255,0,tg.ttl+150)end;g=2;if tg.tgz>200 then g=3 elseif tg.tgz>400 then g=5 end;x1,y1=xd+g*c(o),xy+g*s(o)o=o+2*math.pi/3;x2,y2=xd+g*c(o),xy+g*s(o)o=o+2*math.pi/3;x3,y3=xd+g*c(o),xy+g*s(o)if tg.tgz<50 then if tg.lok then stc(255,150,0)screen.drawText(xd-4,xy,"[+\]")else screen.drawText(xd,xy,"+")end else if tg.lok then stc(255,150,0)tria(x1,y1,x2,y2,x3,y3)else screen.drawTriangle(x1,y1,x2,y2,x3,y3)end;dL(x1,y1,x1+4*s(tg.hd+p4),y1-4*c(tg.hd+p4))end end;function cdH(o,n)hd=cm-math.atan(n.spdy-o.spdy,n.spdx-o.spdx)-p4;return hd end;function idx(j,k,p)for e,b in pairs(j)do if k<=b.x+2 and k>=b.x-2 and p<=b.y+2 and p>=b.y-2 then return e end end;return nil end;function idM()return{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}end;function mxM(j,q)ra=idM()for e=1,4 do for v=1,4 do sum=0;for i=1,4 do sum=sum+j[e\][i\]*q[i\][v\]end;ra[e\][v\]=sum end end;return ra end;function
mxapp(m,k,p,x)rx=m[1\][1\]*k+m[1\][2\]*p+m[1\][3\]*x+m[1\][4\]ry=m[2\][1\]*k+m[2\][2\]*p+m[2\][3\]*x+m[2\][4\]rz=m[3\][1\]*k+m[3\][2\]*p+m[3\][3\]*x+m[3\][4\]return rx,ry,rz end;function mRx(j)return{{1,0,0,0},{0,c(j),-s(j),0},{0,s(j),c(j),0},{0,0,0,1}}end;function mRy(j)return{{c(j),0,s(j),0},{0,1,0,0},{-s(j),0,c(j),0},{0,0,0,1}}end;function mRz(j)return{{c(j),-s(j),0,0},{s(j),c(j),0,0},{0,0,1,0},{0,0,0,1}}end;function mxT(k,p,x)return{{1,0,0,k},{0,1,0,p},{0,0,1,x},{0,0,0,1}}end;function cpT(y,z,A,tg,r,B,p)mxc=mxM(mxT(y,-z,A),mxM(mRz(-p),mxM(mRy(-B),mRx(-r))))Txr=tg.d*c(tg.az)*c(tg.el)tyr=tg.d*s(tg.az)*c(tg.el)tzt=tg.d*s(tg.el)Tx,Ty,Tz=mxapp(mxc,Txr,tyr,tzt)return Tx,-Ty,Tz end
https://redd.it/1k84z5n
@r_lua
https://redd.it/1k84z5n
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I made a little rock paper scissors program inspired by a recent post
Idk why but seeing this post https://www.reddit.com/r/lua/s/eWJooyqrJZ
Just gave me an itch to remake it, anyway:
https://redd.it/1k8gezl
@r_lua
Idk why but seeing this post https://www.reddit.com/r/lua/s/eWJooyqrJZ
Just gave me an itch to remake it, anyway:
local moves = {
rock = {rock = "Draw", paper = "Loss", scissors = "Win!"},
paper = {rock = "Win!", paper = "Draw", scissors = "Loss"},
scissors = {rock = "Loss", paper = "Win!", scissors = "Draw"}
}
local function GetRandMove(randNum)
local n = 0
local randNum = math.random(1, 3)
for k, _ in pairs(moves) do
n = n + 1
if randNum == n then return k end
end
end
local function sleep(n)
local t = os.time() + n
while os.time() < t do end
end
print([[
Time to Play:
--------
rock
paper
scissors
--------
]])
while true do
print("\nYour Move: ")
local PlayerInput = io.read()
local BotMove = GetRandMove()
print(BotMove, "\n")
sleep(.2)
print(moves[PlayerInput][BotMove])
sleep(.4)
::playagain::
print("\ntype y to play again or x to quit: \n")
local playAgain = io.read()
if playAgain == "x" then
print("Goodbye!")
break
elseif playAgain == "y" then
print("\nAlright!\n")
else
goto playagain
end
end
https://redd.it/1k8gezl
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Yo guys, I have a question about the book
Is the book still relevant? And do you think it's worth buying or should I focus on learning from the internet?
https://redd.it/1k8jpsx
@r_lua
Is the book still relevant? And do you think it's worth buying or should I focus on learning from the internet?
https://redd.it/1k8jpsx
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I'm trying to make a nice TV weather app, to show the potential and validate my cross-platform framework.
https://redd.it/1k8t3z7
@r_lua
https://redd.it/1k8t3z7
@r_lua
Is there ANY difference between these two Lua snippets?
Snippet 1:
local function f(x,y)
local y = y or 1 -- Note: "local" here.`
do_something(x,y)
end
Snippet 2:
local function f(x,y)
y = y or 1 -- Note: no "local" here.
do_something(x,y)
end
I know why this pattern is often used but is there any situation whatsoever where these two snippets do not behave identically? If Lua version matters, I am specifically interested in LuaJIT. Also, if it matters, let's assume x and y are simple Lua values. They are **not** objects and don't have metatables.
https://redd.it/1k93frj
@r_lua
Snippet 1:
local function f(x,y)
local y = y or 1 -- Note: "local" here.`
do_something(x,y)
end
Snippet 2:
local function f(x,y)
y = y or 1 -- Note: no "local" here.
do_something(x,y)
end
I know why this pattern is often used but is there any situation whatsoever where these two snippets do not behave identically? If Lua version matters, I am specifically interested in LuaJIT. Also, if it matters, let's assume x and y are simple Lua values. They are **not** objects and don't have metatables.
https://redd.it/1k93frj
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Where can i learn luau?
I am a very early stage roblox game developer and I need to know where is the best option to learn luau. I have been on the same youtube, there are few lessons. I read the documentation - it is unclear. What do you suggest me to do? Maybe I'm writing to the wrong community, but I still need help.
https://redd.it/1k9bqjt
@r_lua
I am a very early stage roblox game developer and I need to know where is the best option to learn luau. I have been on the same youtube, there are few lessons. I read the documentation - it is unclear. What do you suggest me to do? Maybe I'm writing to the wrong community, but I still need help.
https://redd.it/1k9bqjt
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Can nested loop have different types of loops within?
for example
for initialization, min/max value, iteration --yes this is numeric for idc
do
--insert stuff for 1st loop
while (condition)
do
--insert stuff for 2nd loop
repeat
--insert stuff for 3rd loop
until (condition)
end
end
i was wondering if it's possible to do so, since in many instance, nested loops will use loops of the same type...
https://redd.it/1k9ci93
@r_lua
for example
for initialization, min/max value, iteration --yes this is numeric for idc
do
--insert stuff for 1st loop
while (condition)
do
--insert stuff for 2nd loop
repeat
--insert stuff for 3rd loop
until (condition)
end
end
i was wondering if it's possible to do so, since in many instance, nested loops will use loops of the same type...
https://redd.it/1k9ci93
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lua by example?
I'm thinking of developing a Lua by example. Is this something the community would like to see?
https://redd.it/1k9qek4
@r_lua
I'm thinking of developing a Lua by example. Is this something the community would like to see?
https://redd.it/1k9qek4
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Advice
Hi. New here. And to Lua as a whole. I am currently learning Lua to embed it into C++ and possibly use it together with the C++ inline assembler for game development. However Lua is not a walk in the park. The basics of Lua are. And I am stuck there. The basics. Actually, outside of the basic input output, data type conversions (Tostring/tonumber), io.open()/ file:read() / file:close(), os.execute() and maybe "require", i cant say i understand much else.. Trust me i tried but this isnt as easy as promised.. Lua has a very special complexity surrounding it that you only discover after starting..
What advice do you have for a freshman college student like me learning Lua. I should add this is not a part of the program I am doing. Its just a personal interest. How did you master Lua or at least know enough of it to produce a game in it either in pure Lua or Lua embedded in C.
https://redd.it/1kbpn57
@r_lua
Hi. New here. And to Lua as a whole. I am currently learning Lua to embed it into C++ and possibly use it together with the C++ inline assembler for game development. However Lua is not a walk in the park. The basics of Lua are. And I am stuck there. The basics. Actually, outside of the basic input output, data type conversions (Tostring/tonumber), io.open()/ file:read() / file:close(), os.execute() and maybe "require", i cant say i understand much else.. Trust me i tried but this isnt as easy as promised.. Lua has a very special complexity surrounding it that you only discover after starting..
What advice do you have for a freshman college student like me learning Lua. I should add this is not a part of the program I am doing. Its just a personal interest. How did you master Lua or at least know enough of it to produce a game in it either in pure Lua or Lua embedded in C.
https://redd.it/1kbpn57
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
The first stage of my indie game, made with my own engine, is ready
The game https://reprobate.carimbo.run
Made with Carimbo, a home made (by me) 2D engine.
https://github.com/willtobyte/carimbo
The game is written in Lua.
Pixel Art by Aline
https://linktr.ee/dandelion.pixelart
Any feedback is more than welcome.
https://redd.it/1kc9rw7
@r_lua
The game https://reprobate.carimbo.run
Made with Carimbo, a home made (by me) 2D engine.
https://github.com/willtobyte/carimbo
The game is written in Lua.
Pixel Art by Aline
https://linktr.ee/dandelion.pixelart
Any feedback is more than welcome.
https://redd.it/1kc9rw7
@r_lua
GitHub
GitHub - willtobyte/carimbo: A 2D game engine developed in modern C++ using SDL, an Entity-Component-System (ECS) architecture…
A 2D game engine developed in modern C++ using SDL, an Entity-Component-System (ECS) architecture, and Box2D. It features Lua noscripting and is designed for web portability via WebAssembly - willtob...
trying to rewrite lua-resty-fastcgi but it fails to connects
I am trying to rewrite FastCGI extension which was written for Lua Resty module of NGINX by benagricola, but it keeps on failing to connect to any PHP-FastCGI server (throws
I am using the extension like this
set $cginoscriptname '';
location ~ ^/@FastCGI(/+)?(((a-zA-Z0-9\_\-+(/+))+)?(a-zA-Z0-9\-\_+\.a-zA-Z0-9+))? {
internal;
ifmodifiedsince off;
contentbyluablock {
local fastcgi = require "fastcgi"
local fcgi = setmetatable({}, fastcgi)
fcgi:connect("127.0.0.1", 25680)
local ok, err = fcgi:request({
noscriptfilename = ngx.var"document_root" .. ngx.var"cgi_noscript_name",
noscriptname = ngx.var["cginoscriptname"],
documentroot = ngx.var"document_root",
serverport = ngx.var["balancerport"],
pathinfo = ngx.var["fastcgipathinfo"],
querystring = ngx.var"query_string",
requesturi = ngx.var["requesturi"],
documenturi = ngx.var["requesturi"],
serverprotocol = ngx.var["serverprotocol"],
requestmethod = ngx.var["requestmethod"],
geoip2datacountrycode = ngx.var["geoip2datacountrycode"],
geoip2datacountryname = ngx.var["geoip2datacountryname"],
geoip2datacityname = ngx.var["geoip2datacityname"]
}, {
cachedict = "fastcgiCache",
cachevalid = 300,
keepalive = true,
keepalivetimeout = 120000,
keepalivepoolsize = 100,
hideheaders = { "X-Powered-By", "X-Page-Speed", "X-Application-Version", "X-Varnish", "Last-Modified", "Cache-Control", "Vary", "X-CF-Powered-By" },
intercepterrors = true,
readtimeout = 60000,
cacheMethods = { "GET" },
headerchunksize = 50 1024,
body_chunk_size = 30 1024
})
if not ok then
ngx.exit(ngx.HTTPBADGATEWAY)
end
}
include /etc/nginx/fastcgiparams;
accesslog on;
}
and in my PATH Resolver (off-topic, but I have to include it in my question)
local uri = ngx.var"request_uri" or "/"
if type(uri) ~= "string" then
ngx.log(ngx.ERR, "URI is not a string: ", type(uri))
uri = "/"
end
ngx.log(ngx.DEBUG, "Request URI: ", uri or "Unknown!")
ngx.log(ngx.DEBUG, "URI: ", ngx.var"uri" or "Unknown!")
local PATH = ngx.var"document_root" .. uri
local PATH = string.match(PATH, "^[^?]*")
if not PATH or PATH == 1 then
PATH = PATH
end
local file, err = io.open(PATH, "rb")
if not file then
ngx.log(ngx.ERR, "Failed to open file: " .. err)
ngx.status = ngx.HTTPNOTFOUND
ngx.exit(ngx.HTTPNOTFOUND)
return
end
file:close()
ngx.var["cginoscriptname"] = ngx.var["uri"]
local res = ngx.location.capture("/@FastCGI", {
-- method = ngx.HTTPGET,
args = ngx.var"args",
})
ngx.status = res.status
for k, v in pairs(res.header) do
ngx.headerk = v
end
ngx.print(res.body)
ngx.log(ngx.DEBUG, "#1 : " .. uri)
and my extension fork
local ngx = require "ngx"
local bit = require "bit"
local binutil = require 'resty.binutil'
local M = {}
M.index = M
local FCGI = {
HEADERLEN = 0x08,
I am trying to rewrite FastCGI extension which was written for Lua Resty module of NGINX by benagricola, but it keeps on failing to connect to any PHP-FastCGI server (throws
fastCGI : recv header error: closed which means that FastCGI is not available) i tried adjusting the timeout but it didn't workI am using the extension like this
set $cginoscriptname '';
location ~ ^/@FastCGI(/+)?(((a-zA-Z0-9\_\-+(/+))+)?(a-zA-Z0-9\-\_+\.a-zA-Z0-9+))? {
internal;
ifmodifiedsince off;
contentbyluablock {
local fastcgi = require "fastcgi"
local fcgi = setmetatable({}, fastcgi)
fcgi:connect("127.0.0.1", 25680)
local ok, err = fcgi:request({
noscriptfilename = ngx.var"document_root" .. ngx.var"cgi_noscript_name",
noscriptname = ngx.var["cginoscriptname"],
documentroot = ngx.var"document_root",
serverport = ngx.var["balancerport"],
pathinfo = ngx.var["fastcgipathinfo"],
querystring = ngx.var"query_string",
requesturi = ngx.var["requesturi"],
documenturi = ngx.var["requesturi"],
serverprotocol = ngx.var["serverprotocol"],
requestmethod = ngx.var["requestmethod"],
geoip2datacountrycode = ngx.var["geoip2datacountrycode"],
geoip2datacountryname = ngx.var["geoip2datacountryname"],
geoip2datacityname = ngx.var["geoip2datacityname"]
}, {
cachedict = "fastcgiCache",
cachevalid = 300,
keepalive = true,
keepalivetimeout = 120000,
keepalivepoolsize = 100,
hideheaders = { "X-Powered-By", "X-Page-Speed", "X-Application-Version", "X-Varnish", "Last-Modified", "Cache-Control", "Vary", "X-CF-Powered-By" },
intercepterrors = true,
readtimeout = 60000,
cacheMethods = { "GET" },
headerchunksize = 50 1024,
body_chunk_size = 30 1024
})
if not ok then
ngx.exit(ngx.HTTPBADGATEWAY)
end
}
include /etc/nginx/fastcgiparams;
accesslog on;
}
and in my PATH Resolver (off-topic, but I have to include it in my question)
local uri = ngx.var"request_uri" or "/"
if type(uri) ~= "string" then
ngx.log(ngx.ERR, "URI is not a string: ", type(uri))
uri = "/"
end
ngx.log(ngx.DEBUG, "Request URI: ", uri or "Unknown!")
ngx.log(ngx.DEBUG, "URI: ", ngx.var"uri" or "Unknown!")
local PATH = ngx.var"document_root" .. uri
local PATH = string.match(PATH, "^[^?]*")
if not PATH or PATH == 1 then
PATH = PATH
end
local file, err = io.open(PATH, "rb")
if not file then
ngx.log(ngx.ERR, "Failed to open file: " .. err)
ngx.status = ngx.HTTPNOTFOUND
ngx.exit(ngx.HTTPNOTFOUND)
return
end
file:close()
ngx.var["cginoscriptname"] = ngx.var["uri"]
local res = ngx.location.capture("/@FastCGI", {
-- method = ngx.HTTPGET,
args = ngx.var"args",
})
ngx.status = res.status
for k, v in pairs(res.header) do
ngx.headerk = v
end
ngx.print(res.body)
ngx.log(ngx.DEBUG, "#1 : " .. uri)
and my extension fork
local ngx = require "ngx"
local bit = require "bit"
local binutil = require 'resty.binutil'
local M = {}
M.index = M
local FCGI = {
HEADERLEN = 0x08,