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

test[m8n] 11 sending messages


--Instantiation
if (smalltalk.Object["$fn"]()==nil) then error("Instantiating Object") end
if (smalltalk.Object["$fn"]()["$klass"]["$className"]~="Object") then error("Must be Object") end
if (smalltalk.Point["$fn"]()["$klass"]["$className"]~="Point") then error("Must be Point") end


--Instance messages
--Note that #yourself is implemented in Object
local point=smalltalk.Point["$fn"](); print("point="..tostring(point:yourself()).." is a"..(point["$klass"]["$className"]))

--Messages implemented in the class of the receiver
local point=smalltalk.Point["$fn"](); print("point x="..tostring(point:x()))

local point=smalltalk.Point["$fn"](); point:x_y_(5,10); print("point x="..(point:x()).." y="..(point:y()))


--Class messages
if (smalltalk.Object:constructEventsTriggered()[1]~="changed") then error("Should return 'changed'") end
if (smalltalk.Object:eventsTriggered()[1]~="changed") then error("Should return 'changed'") end

--uses of #new and #basicNew
local assoc=smalltalk.Association:new(); print("Association new ="..tostring(assoc:key()).."->"..tostring(assoc:value()))
local assoc=smalltalk.Association:key_value_("hello","world"); print("assoc "..tostring(assoc:key()).."->"..tostring(assoc:value()))

local point=smalltalk.Point:new(); print("Point new x="..tostring(point:x()).." y="..tostring(point:y()))
local point=smalltalk.Point:zero(); print("Zero x="..(point:x()).." y="..(point:y()))

--note that the following expression will fail (in Point>>#x:) while #isNil is not implemented
local point=smalltalk.Point:x_y_(5,10); print("point x="..(point:x()).." y="..(point:y()))


--Accessing native API
if ((type(smalltalk.Smalltalk:current()))~="table") then error("Must be table") end

for i,v in pairs(smalltalk.Smalltalk:current():classes()) do print(i,v["$className"]) end
print("Number of S8 classes in this system="..(#smalltalk.Smalltalk:current():classes()))