File: sample_state.lua

package info (click to toggle)
lua-rings 1.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 256 kB
  • sloc: ansic: 278; sh: 20; makefile: 17
file content (25 lines) | stat: -rw-r--r-- 539 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- $Id: sample_state.lua,v 1.2 2006/07/25 14:09:45 tomas Exp $

require"rings"

local init_cmd = [[
stable = 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 ()

print("OK!")