PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/lua/member_pointer_runme.lua

#
Lua | 43 lines | 22 code | 13 blank | 8 comment | 2 complexity | d90476c79c980eb5f4258869357433f4 MD5 | raw file
 1--Example using pointers to member functions
 2
 3require("import")	-- the import fn
 4import("member_pointer")	-- import code
 5
 6for k,v in pairs(member_pointer) do _G[k]=v end
 7
 8function check(what, expected, actual)
 9	assert(expected == actual,"Failed: "..what.." Expected: "..expected.." Actual: "..actual)
10end
11
12-- Get the pointers
13area_pt = areapt()
14perim_pt = perimeterpt()
15
16-- Create some objects
17s = Square(10)
18
19-- Do some calculations
20check ("Square area ", 100.0, do_op(s,area_pt))
21check ("Square perim", 40.0, do_op(s,perim_pt))
22
23-- Try the variables
24-- these have to still be part of the 'member_pointer' table
25memberPtr = member_pointer.areavar
26memberPtr = member_pointer.perimetervar
27
28check ("Square area ", 100.0, do_op(s,member_pointer.areavar))
29check ("Square perim", 40.0, do_op(s,member_pointer.perimetervar))
30
31-- Modify one of the variables
32member_pointer.areavar = perim_pt
33
34check ("Square perimeter", 40.0, do_op(s,member_pointer.areavar))
35
36-- Try the constants
37memberPtr = AREAPT
38memberPtr = PERIMPT
39memberPtr = NULLPT
40
41check ("Square area ", 100.0, do_op(s,AREAPT))
42check ("Square perim", 40.0, do_op(s,PERIMPT))
43