Hello!
On Wed, May 21, 2014 at 10:28 PM, 朱茂海 wrote:
> function Guard:addToIptables(ip)
> local cmd = "sudo /sbin/iptables -I INPUT -p tcp -s "..ip.." --dport 80 -j
> DROP"
> os.execute(cmd)
> end
>
你上面那一行
function Guard:addToIptables(ip)
其实等价于
function Guard:addToIptables(Guard, ip)
所以形参“ip”其实是这个函数的第二个参数。
> 想问的是:当执行ngx.thread.spawn(Guard.addToIptables,ip)时,函数addToIptables没有接收到ip变量,请问这个是哪里错了,谢谢各位啦。
>
你这里通过 ngx.therad.spawn() 传递的“ip”实参其实传给了 addToIptables 函数的第一个参数,即形参“Guard”.
所以你在 Lua 代码里面使用 : 和 . 时最好悠着点。它们并不是可以随便互换的。
Regards,
-agentzh