--[[ Movable and Named Objects Test Driver Improved Version Using Modules H. Conrad Cunningham, Professor Computer and Information Science University of Mississippi Developed for CSci 658, Software Language Engineering, Fall 2013 1234567890123456789012345678901234567890123456789012345678901234567890 2013-10-09: Moved example code to module and separated this test driver --]] -- Load Improved Movable Objects and Names Module local mv = require "movable2" -- Local names for convenience local Vector, Movable, Point = mv.Vector, mv.Movable, mv.Point local Figure, Line, Circle = mv.Figure, mv.Line, mv.Circle local MovableList, MovableName = mv.MovableList, mv.MovableName local Named, Name = mv.Named, mv.Name local makeClass, isInstanceOf = mv.makeClass, mv.isInstanceOf -- Function "show_data" converts raw Lua data structures to strings to -- assist in debugging and testing. This is borrowed from the Complex -- Number package. local function show_data(d) if type(d) == "table" then local res = {} for k,v in pairs(d) do res[#res+1] = "[" .. show_data(k) .. "] = " .. show_data(v) end return "(" .. table.concat(res, ", ") .. ")" else return tostring(d) end end -- Some PRELIMINARY testing code local disp = Vector:make(10.0, 10.0) local origin = Point:make(0.0,0.0) local unit = Point:make(1.0,1.0) local diag = Line:make(origin,unit) local circ02 = Circle:make(origin,2.0) local circ12 = Circle:make(unit,2.0) local list = {diag,circ12,unit} local mlist = MovableList:make(list) local aa = Name:make("AA",unit) local bb = aa:giveName("BB") local mn = MovableName:make(Name:make("zzz",unit)) local xx = MovableName:make(Name:make("zzz",unit)) :getObject(): getX() print(tostring(xx))