<div>
<span style="font-size: 14px;">I would advise leaving the local keyword. Local variable lookups are faster in Lua, and more importantly it's best to restrict the variable's scope to the smallest scope you'll use it in. Even if you're using the variable at the scope of an entire script, you should declare it local to the script -- global variables are accessed beyond the actual script they are in, as illustrated by the following example:
</span></div><div><span style="font-size: 14px;"><br></span></div><div><span style="font-size: 14px;">test1.lua:</span></div><div><span style="font-size: 14px;"><br></span></div><div><div><font face="Comic Sans MS" style="font-size: 14px;">require "test2"</font></div><div><font face="Comic Sans MS" style="font-size: 14px;"><br></font></div><div><font face="Comic Sans MS" style="font-size: 14px;">print(string.format("foo in test1 is: %s", tostring(foo)))</font></div><div><font face="Comic Sans MS" style="font-size: 14px;">print(string.format("baz in test1 is: %s", tostring(baz)))</font></div></div><div><span style="font-size: 14px;"><br></span></div><div><span style="font-size: 14px;">test2.lua:</span></div><div><span style="font-size: 14px;"><br></span></div><div><div><font face="Comic Sans MS" style="font-size: 14px;">foo = "bar"</font></div><div><font face="Comic Sans MS" style="font-size: 14px;">local baz = "bang"</font></div><div><font face="Comic Sans MS" style="font-size: 14px;"><br></font></div><div><font face="Comic Sans MS" style="font-size: 14px;">print(string.format("foo in test2 is: %s", tostring(foo)))</font></div><div><font face="Comic Sans MS" style="font-size: 14px;">print(string.format("baz in test2 is: %s", tostring(baz)))</font></div></div><div><span style="font-size: 14px;"><br></span></div><div><span style="font-size: 14px;">Output:</span></div><div><span style="font-size: 14px;"><br></span></div><div><div><span style="font-size: 14px;">foo in test2 is: bar</span></div><div><span style="font-size: 14px;">baz in test2 is: bang</span></div><div><span style="font-size: 14px;">foo in test1 is: bar</span></div><div><span style="font-size: 14px;">baz in test1 is: nil</span></div></div><div><span style="font-size: 14px;"><br></span></div><div><span style="font-size: 14px;">Hope this helps.</span></div><div><span style="font-size: 14px;"><br></span></div><div><span style="font-size: 14px;">hunmonk</span></div>
<div></div>
<p style="color: #A0A0A8;">On Monday, November 26, 2012 at 11:00 AM, Bryant Lee wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div>Remove the local keyword from the variable declaration on sip_request_user1.<br><br><div>On Mon, Nov 26, 2012 at 11:29 AM, Archana Venugopan <span dir="ltr"><<a href="mailto:a.venugopan@mundio.com" target="_blank">a.venugopan@mundio.com</a>></span> wrote:<br><blockquote type="cite"><div>
<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p style="margin: 0px; ">Hi,<u></u><u></u></p>
<p style="margin: 0px; "><u></u> <u></u></p>
<p style="margin: 0px; ">Does anyone know how can we use a variable declared inside if statement outside if block?<u></u><u></u></p>
<p style="margin: 0px; "><u></u> <u></u></p>
<p style="margin: 0px; ">if sip_request_user == nil then<u></u><u></u></p>
<p style="margin: 0px; ">sip_request_user = params:getHeader("sip_request_user")<u></u><u></u></p>
<p style="margin: 0px; ">else<u></u><u></u></p>
<p style="margin: 0px; ">local sip_request_user1 = tonumber(sip_request_user)<u></u><u></u></p>
<p style="margin: 0px; ">end<u></u><u></u></p>
<p style="margin: 0px; "><u></u> <u></u></p>
<p style="margin: 0px; ">In my lua I have something like above and I want to use the variable sip_request_user1 outside if. What can be done?<u></u><u></u></p>
<p style="margin: 0px; "><u></u> <u></u></p>
<p style="margin: 0px; ">Regards,<u></u><u></u></p>
<p style="margin: 0px; ">Archana<span style="font-size:10.0pt"><u></u><u></u></span></p>
<p style="margin: 0px; "><u></u> <u></u></p>
</div>
</div>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></div></blockquote></div><br>
</div><div><div>_________________________________________________________________________</div><div>Professional FreeSWITCH Consulting Services:</div><div><a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a></div><div><a href="http://www.freeswitchsolutions.com">http://www.freeswitchsolutions.com</a></div><div><br></div><div>FreeSWITCH-powered IP PBX: The CudaTel Communication Server</div><div><a href="http://www.cudatel.com">http://www.cudatel.com</a></div><div><br></div><div>Official FreeSWITCH Sites</div><div><a href="http://www.freeswitch.org">http://www.freeswitch.org</a></div><div><a href="http://wiki.freeswitch.org">http://wiki.freeswitch.org</a></div><div><a href="http://www.cluecon.com">http://www.cluecon.com</a></div><div><br></div><div>FreeSWITCH-users mailing list</div><div><a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a></div><div><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a></div><div>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a></div><div><a href="http://www.freeswitch.org">http://www.freeswitch.org</a></div></div></div></span>
</blockquote>
<div>
<br>
</div>