From: John L. <jr...@us...> - 2007-02-28 00:47:38
|
Update of /cvsroot/wxlua/wxLua/docs In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv7230/wxLua/docs Modified Files: wxlua.html Log Message: add a little more about the lua language Index: wxlua.html =================================================================== RCS file: /cvsroot/wxlua/wxLua/docs/wxlua.html,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** wxlua.html 5 Feb 2007 23:23:56 -0000 1.12 --- wxlua.html 28 Feb 2007 00:47:33 -0000 1.13 *************** *** 111,119 **** <ul> ! <li>Comments</li> <ul> ! <li>Line comments are marked by --</li> <li>Block Comments are <i>--[[ multiple line comment ]]</i></li> --- 111,120 ---- <ul> ! <li><b>Comments</b></li> <ul> ! <li>Line comments are marked by <i>-- rest of line is ! commented</i></li> <li>Block Comments are <i>--[[ multiple line comment ]]</i></li> *************** *** 121,125 **** </ul> ! <li>Variables</li> <ul> --- 122,126 ---- </ul> ! <li><b>Variables</b></li> <ul> *************** *** 137,150 **** variable only temporarily supersedes the global.</li> </ul> ! <li>Lua Types</li> <ul> ! <li>nil : A special value meaning NULL or nothing, all variables that are not assigned a value are nil.</li> ! <li>Boolean : true or false, nil works as false </li> <ul> --- 138,157 ---- variable only temporarily supersedes the global.</li> + <li>Use the function <i>type(var_name)</i> to + get the type as a string, "string", "number", "boolean", "table", + "userdata", "function".</li> + </ul> ! <li><b>Lua Types</b></li> <ul> ! <li><b>nil</b> : A special value meaning NULL or ! nothing, all variables that are not assigned a value are nil.</li> ! <li><b>boolean</b> : true or false, nil works as ! false </li> <ul> *************** *** 152,156 **** <li>Note: <i>"a = 0; if a then print(a) end"</i> evaluates "a" to ! true since it has a value, eg. not nil.</li> </ul> --- 159,163 ---- <li>Note: <i>"a = 0; if a then print(a) end"</i> evaluates "a" to ! true since it has a value, eg. not nil, use <i>"a ~= 0"</i>.</li> </ul> *************** *** 160,180 **** <ul> ! <li>Numbers : All numbers in Lua are double valued floating point numbers. </li> <ul> ! <li><i>mynumber = (1+ 2 * 3 / (4 * 1) )*math.pow(2, 4)</i></li> </ul> ! <li>Strings : Strings in lua can have embedded nulls "\0" and follow the same escape characters as C.</li> <ul> <li><i>mystring = "How are 'you'!"</i> or <i>mystring = 'How ! are\t"You"!\n'</i> are both valid</li> <li><i>mystring = [[How are "'you'"!]]</i> --- 167,202 ---- <ul> ! <li><b>number</b> : All numbers in Lua are double ! valued floating point numbers. </li> <ul> ! <li><i>mynumber = (1E1+ 2e-2 * 3.14 / (4 * 1) ! )*math.pow(2.5e+2, 4)</i></li> ! ! <li>Variables can be coerced into numbers using the ! function <i>tonumber(variable)</i> which returns <i>nil</i> ! on failure.</li> ! ! <li>Additional math functions are in the <i>math</i> ! table.</li> </ul> ! <li><b>string</b> : Strings in lua can have ! embedded nulls "\0" and follow the same escape characters as C.</li> <ul> + <li>Strings are all hashed so that there is only one copy + of a particular string stored at any one time no matter how many + variables reference it.</li> + <li><i>mystring = "How are 'you'!"</i> or <i>mystring = 'How ! are\t"You"!\n'</i> are both valid since either " or ' can be used ! to quote strings.</li> <li><i>mystring = [[How are "'you'"!]]</i> *************** *** 190,198 **** "..str2.." "..tostring(2).."!"</i></li> </ul> </ul> ! <li>Tables : Tables can be indexed by numbers, strings, functions, other tables...</li> --- 212,232 ---- "..str2.." "..tostring(2).."!"</i></li> + <li>Numbers can be typically coerced into strings as <i>("A + "..1)</i>, but not <i>(1.." A")</i> since in the + second case the string "A" cannot be coerced into a number.</li> + </ul> + <li>Variables can be coerced into strings using the + function <i>tostring(variable)</i> which returns <i>nil</i> + on failure. </li> + + <li>Additional string functions are in the <i>string</i> + table.</li> + </ul> ! <li><b>table</b> : Tables can be indexed by ! numbers, strings, functions, other tables...</li> *************** *** 205,209 **** <li><i>mytable = { ["index1"] = 1, "first value", "second ! value", ["index2"] = 2 }</i></li> <ul> --- 239,243 ---- <li><i>mytable = { ["index1"] = 1, "first value", "second ! value", index2 = 2 }</i></li> <ul> *************** *** 222,227 **** created</li> ! <li>Clear values by setting them to nil : mytable.index1 ! = nil</li> <li>The length operator <i>#mytable</i> --- 256,262 ---- created</li> ! <li>Clear values by setting them to <i>nil</i> ! : <i>mytable.index1 ! = nil</i></li> <li>The length operator <i>#mytable</i> *************** *** 255,259 **** </ul> ! <li>Functions :</li> <ul> --- 290,294 ---- </ul> ! <li><b>function</b> :</li> <ul> *************** *** 946,950 **** </ul> ! <li><b>Extending classes</b> </li> <ul> --- 981,985 ---- </ul> ! <li><b>Extending classes</b> </li> <ul> *************** *** 952,964 **** <li>You cannot arbitrarily override "virtual" functions in wxLua as this must be done in C++. The class must be subclassed and ! 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. Examples of virtual functions that must or can be ! overridden are in wxLuaPrintout class, see the printing sample, and wxLuaHtmlWindow, see html sample. The only virtual functions that you can override are marked with comments in the binding ! files and wxluaref.htm. </li> <li>You may also add your own functions to classes that --- 987,999 ---- <li>You cannot arbitrarily override "virtual" functions in wxLua as this must be done in C++. The class must be subclassed and ! 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. Examples of virtual functions that must or can be ! overridden are in wxLuaPrintout class, see the printing sample, and wxLuaHtmlWindow, see html sample. The only virtual functions that you can override are marked with comments in the binding ! files and wxluaref.htm. </li> <li>You may also add your own functions to classes that *************** *** 970,977 **** <ul> ! <li>Example : <i>"r = wx.wxRect(1,2,3,4); r.PrintXY = function(self) print(self:GetX(), self:GetY()) end; r:PrintXY()"</i> adds the function PrintXY to ! the wxRect instance r. The userdata, class instance, r is passed to the lua function as the parameter "self" which is pushed onto the stack when the PrintXY function is called with the ":" notation.</li> --- 1005,1012 ---- <ul> ! <li>Example : <i>"r = wx.wxRect(1,2,3,4); r.PrintXY = function(self) print(self:GetX(), self:GetY()) end; r:PrintXY()"</i> adds the function PrintXY to ! the wxRect instance r. The userdata, class instance, r is passed to the lua function as the parameter "self" which is pushed onto the stack when the PrintXY function is called with the ":" notation.</li> *************** *** 983,990 **** <li>You may also create the lua function beforehand and then assign it to the rect object. <i>"function ! wxRect_PrintXY_func(self) print(self:GetX(), self:GetY()) end; r1 = wx.wxRect(1,2,3,4); r1.PrintXY = wxRect_PrintXY_func; r1:PrintXY()"</i>. ! You can see that using this idea you can make a lua function ! that creates a new wxRect, sets your extra functions for it, and returns it for use.</li> --- 1018,1025 ---- <li>You may also create the lua function beforehand and then assign it to the rect object. <i>"function ! wxRect_PrintXY_func(self) print(self:GetX(), self:GetY()) end; r1 = wx.wxRect(1,2,3,4); r1.PrintXY = wxRect_PrintXY_func; r1:PrintXY()"</i>. ! You can see that using this idea you can make a lua function ! that creates a new wxRect, sets your extra functions for it, and returns it for use.</li> |