1

最小限の例は、実際には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_counterprint(shared_counter)出力しますnil

を使ってみたのですが、奴隷状態でしか使えないstable.get()と書いてあります。stableやっとやってみた

remotedostring("shared_counter = "..count)

これはうまくいきましたが、それが適切な方法であるかどうかはよくわかりません。値テーブルへの直接アクセスで十分だと思いstableますか?

編集:ああ、追加するのを忘れていましたが、問題の主な部分は、マスターからスレーブへの別の方法で通信していることです。

4

1 に答える 1

2

ライブラリはstable、 と呼ばれるマスター状態のグローバル テーブルに値を格納します_state_persistent_table_。明らかに、これは非公開で非公開にするためのものです。

これが気に入らない場合は、内部でstable使用するだけremotedostring()で、自分でそのようなことをするのは難しくありません。

master->slave の場合slave:dostring()は、同様の手法を使用して十分です。

于 2012-05-19T12:07:51.540 に答える