| |||||||||||
| |||||||||||
Functions to include within a test harness
Programming Standards in Lua example from a Well House Consultants training course
More on Programming Standards in Lua [link]
Source code: loadthese.lua Module: U199
--[[
-- ---------------------------------------------------- -- -- header block ;-) -- -- Written by Graham Ellis of Well House Consutants -- Copyright, version, date, support notices -- A test to show the application of some Lua Standards -- -- ---------------------------------------------------- ]] -- ======================================================== function demo(first, second, third) -- Illustrative function to show paramater handling local again = 0 first = first + 5 -- Alters a COPY so value not returned print ("Called with " .. first .. " - " .. second .. " - " .. third) callCounter = callCounter+1 -- CallCounter is Global again = again + 1 fourth = first + second + third return fourth end -- of function demo -- -------------------------------------------------------- function copyright() -- Returns copyright statement for sharing amonst all you code return "\nThis is your copyright statement" end -- of function copyright -- ======================================================== if (arg[0] == "loadthese.lua") then -- Echo out all the Global variables for k,v in pairs(_G) do print (k,v) if (type(v) == "table") then -- Expand tables within tables for k2,v2 in pairs(v) do print ("---> ",k2,v2) end end end -- test the code print (copyright()) again = 0 -- "proof" that "again" in demo is a local variable there callCounter = 0 -- global to be used in "demo" one = 7 two = 12 three = 16 four = demo(one, two, three) print (callCounter, again, one, two, three, four) four = demo(one, two, three) print (callCounter, again, one, two, three, four) -- Could add a unit test such as Lunit or LuaUnit here end -- of code to run in stand-alone mode only --[[ Sample Output wizard:j graham$ lua52 loadthese.lua string table: 0x100102e80 ---> sub function: 0x10001bdd0 ---> upper function: 0x10001bd10 ---> len function: 0x10001c050 ---> rep function: 0x10001cf70 ---> find function: 0x10001e3f0 ---> match function: 0x10001e3e0 ---> char function: 0x10001c380 ---> dump function: 0x10001c4e0 ---> gmatch function: 0x10001c320 ---> reverse function: 0x10001bc50 ---> byte function: 0x10001c1f0 ---> format function: 0x10001c650 ---> gsub function: 0x10001da20 ---> lower function: 0x10001c090 xpcall function: 0x100016990 package table: 0x100100ef0 ---> path /usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua ---> searchers table: 0x100100cb0 ---> cpath /usr/local/lib/lua/5.2/?.so;/usr/local/lib/lua/5.2/loadall.so;./?.so ---> preload table: 0x1001014d0 ---> loadlib function: 0x10001fda0 ---> loaders table: 0x100100cb0 ---> loaded table: 0x1001012c0 ---> config / ; ? ! - ---> searchpath function: 0x10001fce0 ---> seeall function: 0x10001fc50 tostring function: 0x100016ab0 _VERSION Lua 5.2 os table: 0x1001025c0 ---> exit function: 0x10001b680 ---> setlocale function: 0x10001b540 ---> date function: 0x10001b800 ---> getenv function: 0x10001b640 ---> difftime function: 0x10001b770 ---> remove function: 0x10001b5f0 ---> time function: 0x10001b3d0 ---> clock function: 0x10001bbb0 ---> tmpname function: 0x10001b290 ---> rename function: 0x10001b5a0 ---> execute function: 0x10001b700 unpack function: 0x10001ea60 require function: 0x100101580 bit32 table: 0x1001033b0 ---> band function: 0x100017e70 ---> extract function: 0x100017cd0 ---> bor function: 0x100017d90 ---> bnot function: 0x100017b40 ---> arshift function: 0x100017a20 ---> rshift function: 0x100017aa0 ---> rrotate function: 0x100017970 ---> replace function: 0x100017c50 ---> lshift function: 0x100017af0 ---> lrotate function: 0x1000179a0 ---> btest function: 0x100017e40 ---> bxor function: 0x100017d30 pairs function: 0x100017100 next function: 0x100017120 assert function: 0x100017650 rawlen function: 0x100016d70 ipairs function: 0x1000170e0 io table: 0x100101fa0 ---> lines function: 0x10001a460 ---> write function: 0x1000196a0 ---> close function: 0x100019960 ---> flush function: 0x100019f00 ---> open function: 0x10001a290 ---> output function: 0x10001a250 ---> type function: 0x1000196d0 ---> read function: 0x100019e90 ---> stderr file (0x7fff70b91230) ---> stdin file (0x7fff70b91100) ---> input function: 0x10001a270 ---> stdout file (0x7fff70b91198) ---> popen function: 0x100019f40 ---> tmpfile function: 0x1000197d0 rawequal function: 0x100016dd0 collectgarbage function: 0x100017560 arg table: 0x100104290 ---> -1 lua52 ---> 0 loadthese.lua load function: 0x100017180 module function: 0x100101530 rawset function: 0x100016cc0 math table: 0x100103810 ---> log function: 0x10001af20 ---> acos function: 0x10001b220 ---> huge inf ---> ldexp function: 0x10001afd0 ---> pi 3.1415926535898 ---> cos function: 0x10001b0e0 ---> tanh function: 0x10001aac0 ---> pow function: 0x10001ae50 ---> deg function: 0x10001aa10 ---> tan function: 0x10001aa90 ---> cosh function: 0x10001b110 ---> sinh function: 0x10001ab50 ---> random function: 0x10001acd0 ---> randomseed function: 0x10001ab80 ---> frexp function: 0x10001b020 ---> ceil function: 0x10001b140 ---> floor function: 0x10001aca0 ---> rad function: 0x10001a9d0 ---> abs function: 0x10001aa50 ---> sqrt function: 0x10001aaf0 ---> modf function: 0x10001aea0 ---> asin function: 0x10001b1f0 ---> min function: 0x10001ac20 ---> max function: 0x10001aba0 ---> fmod function: 0x10001b060 ---> log10 function: 0x10001aef0 ---> atan2 function: 0x10001b1a0 ---> exp function: 0x10001b0b0 ---> sin function: 0x10001ab20 ---> atan function: 0x10001b170 pcall function: 0x100016f70 copyright function: 0x100103370 demo function: 0x100104e10 type function: 0x100016a60 debug table: 0x1001029f0 ---> getupvalue function: 0x1000185f0 ---> setuservalue function: 0x100018970 ---> debug function: 0x1000193b0 ---> getmetatable function: 0x100018be0 ---> setmetatable function: 0x100018600 ---> setlocal function: 0x100018660 ---> gethook function: 0x100019240 ---> sethook function: 0x100018770 ---> upvalueid function: 0x100018ad0 ---> traceback function: 0x100018470 ---> upvaluejoin function: 0x100018b20 ---> getinfo function: 0x100018ec0 ---> setupvalue function: 0x1000185c0 ---> getuservalue function: 0x100019360 ---> getregistry function: 0x1000183f0 ---> getlocal function: 0x100018c20 getmetatable function: 0x100017420 select function: 0x100016ba0 table table: 0x100101d20 ---> maxn function: 0x10001ed10 ---> pack function: 0x10001ec70 ---> concat function: 0x10001ee30 ---> insert function: 0x10001eba0 ---> sort function: 0x10001e8e0 ---> remove function: 0x10001e970 ---> unpack function: 0x10001ea60 _G table: 0x100100610 ---> string table: 0x100102e80 ---> xpcall function: 0x100016990 ---> package table: 0x100100ef0 ---> tostring function: 0x100016ab0 ---> _VERSION Lua 5.2 ---> os table: 0x1001025c0 ---> unpack function: 0x10001ea60 ---> require function: 0x100101580 ---> bit32 table: 0x1001033b0 ---> pairs function: 0x100017100 ---> next function: 0x100017120 ---> assert function: 0x100017650 ---> rawlen function: 0x100016d70 ---> ipairs function: 0x1000170e0 ---> io table: 0x100101fa0 ---> rawequal function: 0x100016dd0 ---> collectgarbage function: 0x100017560 ---> arg table: 0x100104290 ---> load function: 0x100017180 ---> module function: 0x100101530 ---> rawset function: 0x100016cc0 ---> math table: 0x100103810 ---> pcall function: 0x100016f70 ---> copyright function: 0x100103370 ---> demo function: 0x100104e10 ---> type function: 0x100016a60 ---> debug table: 0x1001029f0 ---> getmetatable function: 0x100017420 ---> select function: 0x100016ba0 ---> table table: 0x100101d20 ---> _G table: 0x100100610 ---> rawget function: 0x100016d20 ---> loadstring function: 0x100017180 ---> print function: 0x100016e20 ---> coroutine table: 0x100101a20 ---> dofile function: 0x100017480 ---> tonumber function: 0x1000176b0 ---> setmetatable function: 0x100016af0 ---> error function: 0x1000174f0 ---> loadfile function: 0x100017370 rawget function: 0x100016d20 loadstring function: 0x100017180 print function: 0x100016e20 coroutine table: 0x100101a20 ---> resume function: 0x100018270 ---> yield function: 0x100017ee0 ---> status function: 0x1000180f0 ---> wrap function: 0x100018370 ---> create function: 0x100018310 ---> running function: 0x100018240 dofile function: 0x100017480 tonumber function: 0x1000176b0 setmetatable function: 0x100016af0 error function: 0x1000174f0 loadfile function: 0x100017370 This is your copyright statement Called with 12 - 12 - 16 1 0 7 12 16 40 Called with 12 - 12 - 16 2 0 7 12 16 40 wizard:j graham$ ]] Learn about this subject
This module and example are covered on the following public courses:
* Learning to program in Lua * Lua Programming * Lua Programming Also available on on site courses for larger groups Books covering this topic
Yes. We have over 700 books in our library. Books
covering Lua are listed here and when you've selected a
relevant book we'll link you on to Amazon to order.
Other Examples
This example comes from our "Programming Standards in Lua" training module. You'll find a description of the topic and some
other closely related examples on the "Programming Standards in Lua" module index page.
Full description of the source code
You can learn more about this example on the training courses listed on this page,
on which you'll be given a full set of training notes.
Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License. Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre. • The Horse's mouth provides a daily tip or thought. • Further resources are available via the resources centre. • All of these resources can be searched through through our search engine • And there's a global index here. Web site author
Purpose of this website
This is a sample program, class demonstration or answer from a
training course. It's main purpose
is to provide an after-course service to customers who have attended our
public private or
on site courses, but the examples are made
generally available under conditions described below.
Conditions of use
Past attendees on our training courses are welcome to use individual
examples in the course of their programming, but must check
the examples they use to ensure that they are suitable for their
job. Remember that some of our examples show you how not to do
things - check in your notes. Well House Consultants take no responsibility
for the suitability of these example programs to customer's needs.
This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details. Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request. |
| ||||||||||
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho PAGE: http://www.wellho.net/resources/ex.php • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb |