最小限の例は、実際にはRings メイン ページの 2 番目の例です。
require"rings"
local init_cmd = [[
require"stable"]]
local count_cmd = [[
count = stable.get"shared_counter" or 0
stable.set ("shared_counter", count + 1)
return count
]]
S = rings.new () -- new state
assert(S:dostring (init_cmd))
print (S:dostring (count_cmd)) -- true, 0
print (S:dostring (count_cmd)) -- true, 1
S:close ()
S = rings.new () -- another new state
assert (S:dostring (init_cmd))
print (S:dostring (count_cmd)) -- true, 2
S:close ()
ただし、の値を取得できませんshared_counter
。print(shared_counter)
出力しますnil
。
を使ってみたのですが、奴隷状態でしか使えないstable.get()
と書いてあります。stable
やっとやってみた
remotedostring("shared_counter = "..count)
これはうまくいきましたが、それが適切な方法であるかどうかはよくわかりません。値テーブルへの直接アクセスで十分だと思いstable
ますか?
編集:ああ、追加するのを忘れていましたが、問題の主な部分は、マスターからスレーブへの別の方法で通信していることです。