73 lines
1.5 KiB
Plaintext
73 lines
1.5 KiB
Plaintext
|
|
// 共有参照とマルチ引数テスト
|
||
|
|
|
||
|
|
print("=== Shared Reference Test ===")
|
||
|
|
|
||
|
|
// 共有されるBox
|
||
|
|
box SharedBox {
|
||
|
|
init { name }
|
||
|
|
|
||
|
|
setName(n) {
|
||
|
|
me.name = n
|
||
|
|
print("SharedBox name: " + n)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3つの引数を受け取るメソッド
|
||
|
|
process(arg1, arg2, arg3) {
|
||
|
|
print("SharedBox processing: " + arg1 + ", " + arg2 + ", " + arg3)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 共有参照を持つBox1
|
||
|
|
box Node1 {
|
||
|
|
init { nodeId, sharedRef }
|
||
|
|
|
||
|
|
setup(id, shared) {
|
||
|
|
me.nodeId = id
|
||
|
|
me.sharedRef = shared
|
||
|
|
print("Node1 setup: " + id)
|
||
|
|
}
|
||
|
|
|
||
|
|
action() {
|
||
|
|
print("Node1 calling shared method...")
|
||
|
|
me.sharedRef.process("data1", "from", me.nodeId)
|
||
|
|
print("Node1 action completed")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 共有参照を持つBox2
|
||
|
|
box Node2 {
|
||
|
|
init { nodeId, sharedRef }
|
||
|
|
|
||
|
|
setup(id, shared) {
|
||
|
|
me.nodeId = id
|
||
|
|
me.sharedRef = shared
|
||
|
|
print("Node2 setup: " + id)
|
||
|
|
}
|
||
|
|
|
||
|
|
action() {
|
||
|
|
print("Node2 calling shared method...")
|
||
|
|
me.sharedRef.process("data2", "from", me.nodeId)
|
||
|
|
print("Node2 action completed")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// テスト
|
||
|
|
print("Creating shared box...")
|
||
|
|
local shared
|
||
|
|
shared = new SharedBox()
|
||
|
|
shared.setName("CentralHub")
|
||
|
|
|
||
|
|
print("Creating nodes...")
|
||
|
|
local node1
|
||
|
|
node1 = new Node1()
|
||
|
|
node1.setup("NodeA", shared)
|
||
|
|
|
||
|
|
local node2
|
||
|
|
node2 = new Node2()
|
||
|
|
node2.setup("NodeB", shared)
|
||
|
|
|
||
|
|
print("Testing actions...")
|
||
|
|
node1.action()
|
||
|
|
node2.action()
|
||
|
|
|
||
|
|
print("Shared reference test completed!")
|