70 lines
1.6 KiB
Plaintext
70 lines
1.6 KiB
Plaintext
|
|
// me回避策テスト
|
|||
|
|
|
|||
|
|
print("=== Me Workaround Test ===")
|
|||
|
|
|
|||
|
|
box TargetBox {
|
|||
|
|
init { name }
|
|||
|
|
|
|||
|
|
deliver(messageType, data, from) {
|
|||
|
|
print("deliver: " + from + " -> " + messageType + " = " + data)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
box CallerBox {
|
|||
|
|
init { target, nodeId }
|
|||
|
|
|
|||
|
|
setup(targetRef) {
|
|||
|
|
me.target = targetRef
|
|||
|
|
me.nodeId = "TestNode"
|
|||
|
|
print("CallerBox setup completed")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
getNodeId() {
|
|||
|
|
return me.nodeId
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 方法1: me.nodeIdを直接使用(元の問題のある方法)
|
|||
|
|
testDirect() {
|
|||
|
|
print("Test 1: Direct me.nodeId usage...")
|
|||
|
|
me.target.deliver("hello", "data1", me.nodeId)
|
|||
|
|
print("Direct test completed")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 方法2: local変数経由
|
|||
|
|
testViaLocal() {
|
|||
|
|
print("Test 2: Via local variable...")
|
|||
|
|
local nodeIdCopy
|
|||
|
|
nodeIdCopy = me.nodeId
|
|||
|
|
me.target.deliver("hello", "data2", nodeIdCopy)
|
|||
|
|
print("Local variable test completed")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 方法3: getterメソッド経由
|
|||
|
|
testViaGetter() {
|
|||
|
|
print("Test 3: Via getter method...")
|
|||
|
|
me.target.deliver("hello", "data3", me.getNodeId())
|
|||
|
|
print("Getter method test completed")
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// テスト実行
|
|||
|
|
print("Creating boxes...")
|
|||
|
|
local target
|
|||
|
|
target = new TargetBox()
|
|||
|
|
|
|||
|
|
local caller
|
|||
|
|
caller = new CallerBox()
|
|||
|
|
caller.setup(target)
|
|||
|
|
|
|||
|
|
print("Testing via local variable...")
|
|||
|
|
caller.testViaLocal()
|
|||
|
|
|
|||
|
|
print("Testing via getter method...")
|
|||
|
|
caller.testViaGetter()
|
|||
|
|
|
|||
|
|
print("Testing direct me access...")
|
|||
|
|
caller.testDirect()
|
|||
|
|
|
|||
|
|
print("If you see this, direct me access worked!")
|
|||
|
|
|
|||
|
|
print("All me workaround tests completed!")
|