From: John L. <jr...@us...> - 2007-06-12 20:36:17
|
Update of /cvsroot/wxlua/wxLua/docs In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv26773/wxLua/docs Modified Files: wxlua.html Log Message: Add bitlib and hopefully clarified using . or : for class member functions, properties, static... Index: wxlua.html =================================================================== RCS file: /cvsroot/wxlua/wxLua/docs/wxlua.html,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** wxlua.html 12 Jun 2007 00:08:36 -0000 1.23 --- wxlua.html 12 Jun 2007 20:36:10 -0000 1.24 *************** *** 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> *************** *** 37,47 **** manipulation, sockets, displaying HTML, and printing to name a few. There is no special initialization required in lua and you can use as ! much or as little of wxWidgets as you like.<br> <h3>References:</h3> wxLua website : <a href="http://wxlua.sourceforge.net">http://wxlua.sourceforge.net</a><br> wxLua Sourceforge page : <a href="http://sourceforge.net/projects/wxlua">http://sourceforge.net/projects/wxlua</a><br> Lua website : <a href="http://www.lua.org">http://www.lua.org</a><br> ! wxWidgets website : <a href="http://www.wxwidgets.org">http://www.wxwidgets.org</a><br> ! User and developer mailing list : wxl...@li...<br> <h2 style="text-decoration: underline;">Contents</h2> <ol> <li><a href="#Version_Information">Version --- 37,51 ---- manipulation, sockets, displaying HTML, and printing to name a few. There is no special initialization required in lua and you can use as ! much or as little of wxWidgets as you like.<br><br>Additionally, ! wxLua adds a library for manipulating the bits of integer numbers using ! the Bitlib library from Reuben Thomas.<br> <h3>References:</h3> wxLua website : <a href="http://wxlua.sourceforge.net">http://wxlua.sourceforge.net</a><br> wxLua Sourceforge page : <a href="http://sourceforge.net/projects/wxlua">http://sourceforge.net/projects/wxlua</a><br> Lua website : <a href="http://www.lua.org">http://www.lua.org</a><br> ! wxWidgets website : <a href="http://www.wxwidgets.org">http://www.wxwidgets.org</a><br>Bitlib ! library : <a href="http://rrt.sc3d.org/Software/Lua/">http://rrt.sc3d.org/Software/Lua/</a><br>User ! and developer mailing list : ! wxl...@li...<br> <h2 style="text-decoration: underline;">Contents</h2> <ol> <li><a href="#Version_Information">Version *************** *** 49,53 **** <li><a href="#Introduction_to_Lua_very_brief">Introduction to Lua ! (very brief)</a></li> <li><a href="#wxLua_Programming_in_Lua">Programming in wxLua</a></li> <li><a href="#wxLua_Samples">wxLua Samples and How --- 53,58 ---- <li><a href="#Introduction_to_Lua_very_brief">Introduction to Lua ! (very brief)</a></li><li><a href="#Bit_Library">Bit ! Library</a></li> <li><a href="#wxLua_Programming_in_Lua">Programming in wxLua</a></li> <li><a href="#wxLua_Samples">wxLua Samples and How *************** *** 263,294 **** 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 doing this, doesn't print # 5.</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 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 --- 268,296 ---- 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 doing this, doesn't print # 5.</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 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 *************** *** 299,304 **** 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> -- the a here is local to the for loop and you CANNOT change it to affect the loop, use break<br> local temp = a * 2<br> print(temp)<br>end<br>print(a) -- a == "hello" since the a in the for loop above was 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 --- 301,305 ---- 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> -- the a here is local to the for loop and you CANNOT change it to affect the loop, use break<br> local temp = a * 2<br> print(temp)<br>end<br>print(a) -- a == "hello" since the a in the for loop above was 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 *************** *** 310,315 **** receive return values that you do not want (e.g. if you only want the second return value, use _ for the first).</li> </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><a name="wxLua_Programming_in_Lua"></a><u>Programming in wxLua</u></h2> Programming in wxLua means that you're writing lua programs using the --- 311,334 ---- receive return values that you do not want (e.g. if you only want the second return value, use _ for the first).</li> </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>wxLua automatically loads a library for manipulating ! the bits of an integer and puts it into the global "bit" table. This is ! because wxWidgets often uses enumeration flags to control the behavior ! of functions and for compactly storing information about the status of ! things. You can easily "or" bits by adding them together and ! this is the preferred method, for example 0x02 + 0x04 = 0x06 or bitwise ! 0110, but 0x01 + 0x03 = 0x04 or bitwise 0100 (oops). If however, you do ! require a true "or" function you have to be a ! little more clever in lua since there are no builtin methods to do ! this. <br><br>wxLua uses the bitlib library written by ! Reuben Thomas and since the code for it is small, it's embedded into ! the wxLua sourcecode. <br><br>All ! function arguments should be integers. The number of bits available for ! logical operations depends on the data type used to represent Lua ! numbers; this is typically 8-byte IEEE floats, which give 53 bits (the ! size of the mantissa).<br>The logical operations start with "b" ! for "bit" to avoid clashing with reserved words; although "xor" isn't a ! reserved word, it seemed better to use "bxor" for consistency.<br><ul><li>bit.bnot(a) returns the one's complement of a</li><li>bit.band(w1,...) returns the bitwise and of the w's</li><li>bit.bor(w1,...) returns the bitwise or of the w's</li><li>bit.bxor(w1,...) returns the bitwise exclusive or of the w's</li><li>bit.lshift(a,b) returns a shifted left b places</li><li>bit.rshift(a,b) returns a shifted logically right b places</li><li>bit.arshift(a,b) returns a shifted arithmetically right b places (works on negative ! numbers too)</li><li>bit.mod(a,b) returns the integer remainder of a divided by b</li></ul><h2><a name="wxLua_Programming_in_Lua"></a><u>Programming in wxLua</u></h2> Programming in wxLua means that you're writing lua programs using the *************** *** 494,498 **** function with. If you <span style="font-style: italic;">really</span> want to use the '.' notation you can pass the "self" in as the first ! parameter.</li> <ul> <li>Example : <i>"size = wx.wxSize(1, 2); size:SetWidth(10); size.SetHeight(size, 11); print(size:GetWidth(), size.GetHeight(size))"</i> where we create --- 513,521 ---- function with. If you <span style="font-style: italic;">really</span> want to use the '.' notation you can pass the "self" in as the first ! parameter. There are two exceptions to the ':' calling convention rule, ! <span style="font-weight: bold;">properties</span> ! and <span style="font-weight: bold;">static</span> ! functions, please see the sections below about why they only use the ! '.' convention.</li> <ul> <li>Example : <i>"size = wx.wxSize(1, 2); size:SetWidth(10); size.SetHeight(size, 11); print(size:GetWidth(), size.GetHeight(size))"</i> where we create *************** *** 506,527 **** <li><b>Property functions</b> allow ! you to read and/or write values to a class using the '.' convention.</li> <ul> <li>These are generated on the fly when the function is ! called and work only for these functions.</li> <ul> <li>GetXXX() ! takes no values and returns one -> ! property name XXX</li> <li>SetXXX() takes one value and ! returns one -> ! property name XXX</li> <li>The Get/Set is removed and you do not use them like ! a function call using (), but rather like accessing a table member. </li> ! </ul> </ul> <ul> <li>Example : <i>"rect = wx.wxRect(wx.wxPoint(1,2), wx.wxSize(3,4)); rect.X = 10; print(rect.X)"</i></li> ! <li>These properties are available for most Get/SetXXX ! class member functions.</li> <li>NOTE : Is this really necessary? Confusing? Useful? I'd stick with the Get/Set functions. - JL</li> </ul> <li><b>Member ! functions</b> allow you to read and/or write to member variables of a class.</li> <ul> <li>Declared in the interface files using the <i>%member</i> --- 529,556 ---- <li><b>Property functions</b> allow ! you to read and/or write values to a class using the '.' convention and ! a shortened name.</li> <ul> <li>These are generated on the fly when the function is ! called on a wxLua userdata and work only for functions ! following these rules.</li> <ul> <li>GetXXX() ! takes no values and returns one. </li> <li>SetXXX() ! takes one value and ! returns none.</li> </ul><li>The Get/Set part of the ! function name is removed leaving only XXX and you do not use them like ! a function call using (), but rather like accessing a table member.</li> ! </ul> <ul> <li>Example : <i>"rect = wx.wxRect(wx.wxPoint(1,2), wx.wxSize(3,4)); rect.X = 10; print(rect.X)"</i></li> ! <li>Note : There is no way to find out from lua if the code used ! a '.' or a ':' to call the function and therefore properties cannot be ! made to work for the ':' calling convention since in that case ! we have to remove the object (the self) that lua automatically pushes ! onto the stack that we don't need or want.</li> <li>Note : ! Are properties really necessary? Confusing? Useful? I'd stick with the Get/Set functions. - JL</li> </ul> <li><b>Member ! variable functions</b> allow you to read and/or write to member variables of a class.</li> <ul> <li>Declared in the interface files using the <i>%member</i> *************** *** 531,535 **** declared for wxPoint : <i>"%rename X %member int x"</i></li> <li>The wxPoint class does not have functions to access ! the x, y variables so we create our own.</li> <li>The <i>%member</i> tag creates functions called Get/Set[variable name] or in this case Getx() and Setx(value), --- 560,564 ---- declared for wxPoint : <i>"%rename X %member int x"</i></li> <li>The wxPoint class does not have functions to access ! the int x, y variables so we create our own.</li> <li>The <i>%member</i> tag creates functions called Get/Set[variable name] or in this case Getx() and Setx(value), *************** *** 545,553 **** functions</b> are part of the table that holds the class and can be called with or without a class ! instance.</li> <ul> <li>Example : <i>f = wx.wxFileName('dummy'); f.GetCwd() == wx.wxFileName.GetCwd()</i></li> <li>Note ! that you use the '.' calling convention since ! static C++ functions do not require the object itself.<br> </li> </ul> <li><b>Enum members</b> are also part of the --- 574,587 ---- functions</b> are part of the table that holds the class and can be called with or without a class ! instance (a userdata).</li> <ul> <li>Example : <i>f ! = wx.wxFileName('dummy'); f.GetCwd() == wx.wxFileName.GetCwd()</i></li> <li>Note ! that you always use the '.' calling convention since ! static C++ functions do not require the object itself or in lua's case ! the userdata.</li><li>See the <span style="font-weight: bold;">properties</span> section ! about the difference between '.' and ':' and why using a ':' cannot be ! made to work reliably when you don't want or need the self pushed onto ! the stack. </li> </ul> <li><b>Enum members</b> are also part of the *************** *** 625,629 **** the virtual functions overridden to check to see if there is a lua function to call instead of the base class function. This has only ! been done for cases where it is necessary, in many cases you can intercept the appropriate wxEvent and change the behavior from within the handler.</li><li>Examples of virtual functions that --- 659,663 ---- the virtual functions overridden to check to see if there is a lua function to call instead of the base class function. This has only ! been done for cases where it is necessary. In many cases you can intercept the appropriate wxEvent and change the behavior from within the handler.</li><li>Examples of virtual functions that *************** *** 663,668 **** 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> --- 697,701 ---- 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> *************** *** 711,716 **** 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> --- 744,748 ---- 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> *************** *** 991,996 **** = ";;../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 --- 1023,1027 ---- = ";;../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 |