[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[m8n] 81 Metatables and Metamethods

-- setup
("(Smalltalk includesKey: #Test) ifFalse: [ Object subclass: #Test ]"):evaluate()
test=smalltalk.Test:new()


-- math operators
("Test prototype basicAt: #__add put: [:a :b| 1 ]"):evaluate()
("Test prototype basicAt: #__sub put: [:a :b| 2 ]"):evaluate()
("Test prototype basicAt: #__mul put: [:a :b| 3 ]"):evaluate()
("Test prototype basicAt: #__div put: [:a :b| 4 ]"):evaluate()
("Test prototype basicAt: #__mod put: [:a :b| 5 ]"):evaluate()
("Test prototype basicAt: #__pow put: [:a :b| 6 ]"):evaluate()
("Test prototype basicAt: #__unm put: [:a :b| 7 ]"):evaluate()
("Test prototype basicAt: #__idiv put: [:a :b| 8 ]"):evaluate()
if (test+123~=1) then error("Must be 1") end
if (34+test~=1) then error("Must be 1") end


-- string operators
("Test prototype basicAt: #__concat put: [:a :b| a class name , b class name ]"):evaluate()
("Test prototype basicAt: #__len put: [:a| 2 ]"):evaluate()
if ((test..(smalltalk.Point:x_y_(5,3)))~="TestPoint") then error("Must be TestPoint") end
if (#test~=2) then error("Must be 2") end


-- cleanup
test=nil
smalltalk.Test:removeFromSystem()


References

See Lua Manual