From: John L. <jr...@us...> - 2007-08-03 14:29:13
|
Update of /cvsroot/wxlua/wxLua/docs In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19961/wxLua/docs Modified Files: wxlua.html Log Message: Add note about ... vararg function inputs Index: wxlua.html =================================================================== RCS file: /cvsroot/wxlua/wxLua/docs/wxlua.html,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** wxlua.html 1 Aug 2007 18:24:13 -0000 1.32 --- wxlua.html 3 Aug 2007 14:29:09 -0000 1.33 *************** *** 1,6 **** <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head> ! <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>wxLua Documentation</title> <meta content="John Labenski" name="author"></head> ! <body><h2><u>wxLua Documentation</u></h2> --- 1,6 ---- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head> ! <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>wxLua Documentation</title> ! <meta content="John Labenski" name="author"></head> <body><h2><u>wxLua Documentation</u></h2> *************** *** 279,310 **** printHi() do return end; print("hi") end</i> which can be useful for debugging functions.</li> </ul> ! </ul><blockquote> <pre>do<br> -- create a new local scope<br> local a = 2<br>end<br></pre> ! </blockquote><ul> <li><b>if (bool) then ... elseif (bool) then ... else ... end</b></li> ! </ul><blockquote> <pre>local a, b, c = 1, 2, 3 -- can assign multiple values<br>a = 1; b = 2; c = 3 -- use ; for multiple lines of code on single line<br>a, b, c = 1, 2, 3 -- this works too<br>if (a == 1) and ((b <= 2) or (c ~= 3)) then <br> print(a+b/c) <br>elseif a == 2 then -- no parentheses necessary<br> print(a)<br>else<br> print(b)<br>end</pre> ! </blockquote><ul> <ul> <li>There is no case statement, but a table[value] = function() ... end may be used to simulate one.</li> <blockquote> ! <pre>mycase = {}<br>mycase[1] = function() print("Hello #1") end<br>mycase[2] = function() print("Hello #2") end<br>...<br>if mycase[value] then<br> mycase[value]()<br>else<br> print("Unknown case value")<br>end</pre> ! </blockquote> </ul> <li><b>while (bool) ... end</b></li> <ul> <li>Note : there is no <i>continue</i> keyword only <i>break</i></li> </ul> ! </ul><blockquote> <pre>function CheckA(val) if val == 5 then return true end end<br>local a = 1<br>while a < 10 do<br> print(a)<br> a = a + 1 -- no increment operator<br> if CheckA(a) then break end<br>end</pre> ! </blockquote><ul> <ul> <li>You can make a "fake" continue by adding a while loop (doesn't print # 5). <br></li> </ul> ! </ul><blockquote><pre>local a = 1<br>while a < 10 do while true do<br> a = a + 1 -- no increment operator<br> if CheckA(a) then <br> break <br> else<br> print(a)<br> end<br>break end end</pre> ! </blockquote><ul> <li><b>repeat ... until (bool)</b></li> <ul> <li>Note : there is no continue keyword only break</li> </ul> ! </ul><blockquote> <pre>local a = 1<br>repeat<br> local temp = a * 2<br> print(temp, type(temp))<br> a = a + 1 -- no increment operator<br>until a > 10</pre> ! </blockquote><ul> <li><b>for var = init_value, end_value [, increment] do --- 279,310 ---- printHi() do return end; print("hi") end</i> which can be useful for debugging functions.</li> </ul> ! </ul><blockquote> <pre>do<br> -- create a new local scope<br> local a = 2<br>end<br></pre></blockquote><ul> ! <li><b>if (bool) then ... elseif (bool) then ... else ... end</b></li> ! </ul><blockquote> <pre>local a, b, c = 1, 2, 3 -- can assign multiple values<br>a = 1; b = 2; c = 3 -- use ; for multiple lines of code on single line<br>a, b, c = 1, 2, 3 -- this works too<br>if (a == 1) and ((b <= 2) or (c ~= 3)) then <br> print(a+b/c) <br>elseif a == 2 then -- no parentheses necessary<br> print(a)<br>else<br> print(b)<br>end</pre></blockquote><ul> ! <ul> <li>There is no case statement, but a table[value] = function() ... end may be used to simulate one.</li> <blockquote> ! <pre>mycase = {}<br>mycase[1] = function() print("Hello #1") end<br>mycase[2] = function() print("Hello #2") end<br>...<br>if mycase[value] then<br> mycase[value]()<br>else<br> print("Unknown case value")<br>end</pre></blockquote> ! </ul> <li><b>while (bool) ... end</b></li> <ul> <li>Note : there is no <i>continue</i> keyword only <i>break</i></li> </ul> ! </ul><blockquote> <pre>function CheckA(val) if val == 5 then return true end end<br>local a = 1<br>while a < 10 do<br> print(a)<br> a = a + 1 -- no increment operator<br> if CheckA(a) then break end<br>end</pre></blockquote><ul> ! <ul> <li>You can make a "fake" continue by adding a while loop (doesn't print # 5). <br></li> </ul> ! </ul><blockquote><pre>local a = 1<br>while a < 10 do while true do<br> a = a + 1 -- no increment operator<br> if CheckA(a) then <br> break <br> else<br> print(a)<br> end<br>break end end</pre></blockquote><ul> ! <li><b>repeat ... until (bool)</b></li> <ul> <li>Note : there is no continue keyword only break</li> </ul> ! </ul><blockquote> <pre>local a = 1<br>repeat<br> local temp = a * 2<br> print(temp, type(temp))<br> a = a + 1 -- no increment operator<br>until a > 10</pre></blockquote><ul> ! <li><b>for var = init_value, end_value [, increment] do *************** *** 317,322 **** it did before the loop. Copy the loop counter variable to a separate variable if you need to save it when breaking for example.</li> </ul> ! </ul><blockquote> <pre>local a = "hello"<br>for a = 1, 10 --[[, increment]] do -- optional increment value, else 1<br> local temp = a * 2<br> print(temp)<br>end<br>print(a) -- a == "hello" since loop counter variable is local to the loop<br></pre> ! </blockquote><ul> <li><b>functions</b></li> <ul> <li>Input any number of values by value, tables are passed by --- 317,322 ---- it did before the loop. Copy the loop counter variable to a separate variable if you need to save it when breaking for example.</li> </ul> ! </ul><blockquote> <pre>local a = "hello"<br>for a = 1, 10 --[[, increment]] do -- optional increment value, else 1<br> local temp = a * 2<br> print(temp)<br>end<br>print(a) -- a == "hello" since loop counter variable is local to the loop<br></pre></blockquote><ul> ! <li><b>functions</b></li> <ul> <li>Input any number of values by value, tables are passed by *************** *** 324,338 **** the value nil, extra inputs are discarded.</li> <li>Return values using the "return" keyword</li> <li>Not all return ! values need to be used and extra ones will be discarded. The symbol "_" is a valid variable name and is often used as a dummy variable to ! receive return values that you do not want (e.g. if you only want the ! second return value, use _ for the first). You may use the select(n, ! ...) function to choose return values to use.</li><li>Tables can be used as containers for input values to functions using the unpack(table, [i, [, j]]) function. This is useful for creating complex inputs to a function or storing them for resuse.</li><ul><li><span style="font-style: italic;">print(string.find(unpack({"Hello", ! "ll", 1, 1})))</span> -> prints "3 4"</li></ul> ! </ul> ! </ul><blockquote> <pre>function DoStuff(a, b, c)<br> a = b*c -- does not change global and/or input number a<br> local function Calc(a)<br> return a*2<br> end<br> <br> return Calc(a)*b*c -- or for multiple values "return a*b*c, a*b"<br>end<br>-- call function<br>a = 10<br>result = DoStuff(a, 1, 2)<br>-- can also put function into a table<br>stuff = {}<br>stuff.DoStuff = DoStuff<br>result = stuff.DoStuff(1, 2, 3)<br>print(a, result) -- "10, 72" since a is not changed</pre> </blockquote><h2 style="text-decoration: underline;"><a name="Bit_Library"></a>Bit Library</h2> --- 324,349 ---- the value nil, extra inputs are discarded.</li> <li>Return values using the "return" keyword</li> <li>Not all return ! values need to be used and extra ones will be discarded. </li><ul><li>The symbol "_" is a valid variable name and is often used as a dummy variable to ! receive return values that you do not want.</li><ul style="font-style: italic;"><li>function GetNums() return 3, 4 end; local _, num2 = GetNums()</li></ul><li>You may also use the <span style="font-style: italic;">select(n, ! ...)</span> function to choose return values to use.</li></ul><li>Tables can be used as containers for input values to functions using the unpack(table, [i, [, j]]) function. This is useful for creating complex inputs to a function or storing them for resuse.</li><ul><li><span style="font-style: italic;">print(string.find(unpack({"Hello", ! "ll", 1, 1})))</span> -> prints "3 4"</li></ul><li>Vararg ! inputs are written as <span style="font-style: italic;">function ! dostuff( ... )</span></li><ul><li>The number of ! args is found using: <span style="font-style: italic;">local ! n = select("#", ...)</span></li><li>The args can be ! converted into table using: <span style="font-style: italic;">local ! args = { ... }</span></li><li>A particular arg can be ! chosen using: <span style="font-style: italic;">local ! arg3 = select(3, ...)</span> </li><ul><li>Note ! <span style="font-style: italic;">select(n, ...)</span> returns ! all args after <span style="font-style: italic;">n</span>, ! but if the left hand side is a single variable the others are ! discarded. See above about using <span style="font-style: italic;">select()</span> ! to pick return values of a function as well.</li></ul></ul> ! </ul></ul><blockquote> <pre>function DoStuff(a, b, c)<br> a = b*c -- does not change global and/or input number a<br> local function Calc(a)<br> return a*2<br> end<br> <br> return Calc(a)*b*c -- or for multiple values "return a*b*c, a*b"<br>end<br>-- call function<br>a = 10<br>result = DoStuff(a, 1, 2)<br>-- can also put function into a table<br>stuff = {}<br>stuff.DoStuff = DoStuff<br>result = stuff.DoStuff(1, 2, 3)<br>print(a, result) -- "10, 72" since a is not changed</pre> </blockquote><h2 style="text-decoration: underline;"><a name="Bit_Library"></a>Bit Library</h2> *************** *** 887,892 **** that creates a new wxRect, sets your extra functions for it, and returns it for use.</li> <ul> </ul> </ul> ! </ul> </ul> ! </ul><h2><a name="wxLua_Samples"></a><u><u>wxLua Samples and How to Run Them</u></u></h2> There are a number of sample programs in the <i style="font-style: italic;">wxLua/samples</i> --- 898,902 ---- that creates a new wxRect, sets your extra functions for it, and returns it for use.</li> <ul> </ul> </ul> ! </ul> </ul></ul><h2><a name="wxLua_Samples"></a><u><u>wxLua Samples and How to Run Them</u></u></h2> There are a number of sample programs in the <i style="font-style: italic;">wxLua/samples</i> *************** *** 935,940 **** directory so you may have to specify a different path depending on where you are running lua.exe from. For more information see <a href="#wrapmodule.wx.lua">wrapmodule.wx.lua</a>. </li> ! </ul> ! </ul><h3><a name="Provided_samples"></a>Provided Samples</h3> <ul> <li><b>bindings.wx.lua</b></li> <ul> --- 945,949 ---- directory so you may have to specify a different path depending on where you are running lua.exe from. For more information see <a href="#wrapmodule.wx.lua">wrapmodule.wx.lua</a>. </li> ! </ul></ul><h3><a name="Provided_samples"></a>Provided Samples</h3> <ul> <li><b>bindings.wx.lua</b></li> <ul> *************** *** 1222,1227 **** = ";;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;"</li> ! </ul> </ul> ! </ul><h2><a name="wxLua_Sourcecode_Modules"></a><u>wxLua Sourcecode Modules</u></h2> wxLua is broken up into "modules" that are compiled into libraries so --- 1231,1235 ---- = ";;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;"</li> ! </ul> </ul></ul><h2><a name="wxLua_Sourcecode_Modules"></a><u>wxLua Sourcecode Modules</u></h2> wxLua is broken up into "modules" that are compiled into libraries so *************** *** 1409,1413 **** wxlua_pushkey_wxLuaReferences(L)</i> for example, to push the value of index to use.<br> ! <ul> <li>wxLuaReferences</li> <ul> <li>Tables indexed on the numeric "tags" that are used as metatables for the userdata pushed into Lua.</li> <ul> <li>The --- 1417,1422 ---- wxlua_pushkey_wxLuaReferences(L)</i> for example, to push the value of index to use.<br> ! <ul> <li>wxLuaReferences</li> <ul> <li>Tables ! indexed on the numeric "tags" that are used as metatables for the userdata pushed into Lua.</li> <ul> <li>The |