diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/luaprocTest2.lua | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/LuaSL/testLua/luaprocTest2.lua b/LuaSL/testLua/luaprocTest2.lua new file mode 100644 index 0000000..7814e42 --- /dev/null +++ b/LuaSL/testLua/luaprocTest2.lua | |||
@@ -0,0 +1,80 @@ | |||
1 | require "luaproc" | ||
2 | |||
3 | result, error_msg = luaproc.createworker() | ||
4 | if not result then print(error_msg) end | ||
5 | result, error_msg = luaproc.createworker() | ||
6 | if not result then print(error_msg) end | ||
7 | result, error_msg = luaproc.createworker() | ||
8 | if not result then print(error_msg) end | ||
9 | result, error_msg = luaproc.createworker() | ||
10 | if not result then print(error_msg) end | ||
11 | |||
12 | count = 0 | ||
13 | |||
14 | for i = 1, 10 do | ||
15 | local proc = [=[ | ||
16 | require "string" | ||
17 | local channel = "channel%d" | ||
18 | local message | ||
19 | |||
20 | result, error_msg = luaproc.newchannel(channel) | ||
21 | if not result then print(error_msg) end | ||
22 | repeat | ||
23 | message = luaproc.receive(channel) | ||
24 | local x, y = string.find(message, "@") | ||
25 | if not x then | ||
26 | x, y = string.find(message, "@") | ||
27 | x, y = string.find(message, "@") | ||
28 | x, y = string.find(message, "@") | ||
29 | x, y = string.find(message, "@") | ||
30 | x, y = string.find(message, "@") | ||
31 | x, y = string.find(message, "@") | ||
32 | x, y = string.find(message, "@") | ||
33 | x, y = string.find(message, "@") | ||
34 | end | ||
35 | until "quit" == message | ||
36 | ]=] | ||
37 | |||
38 | proc = string.format(proc, i) | ||
39 | -- print(proc) | ||
40 | result, error_msg = luaproc.newproc(proc) | ||
41 | if not result then print(error_msg) else count = count + 1 end | ||
42 | end | ||
43 | |||
44 | print("Started " .. count .. " Lua threads.") | ||
45 | |||
46 | mainProc = [=[ | ||
47 | local count = %d | ||
48 | local messages = 0 | ||
49 | local length = 0 | ||
50 | local message = "This is a test message. 56789 12" | ||
51 | |||
52 | if 0 ~= count then | ||
53 | for k = 0, 16 do | ||
54 | for j = 0, 199 do | ||
55 | for i = 1, count do | ||
56 | result, error_msg = luaproc.send("channel" .. i, message) | ||
57 | if not result then print(error_msg .. " " .. i) else | ||
58 | messages = messages + 1 | ||
59 | length = length + #message | ||
60 | end | ||
61 | end | ||
62 | end | ||
63 | message = message .. message | ||
64 | end | ||
65 | |||
66 | for i = 1, count do | ||
67 | result, error_msg = luaproc.send("channel" .. i, "quit") | ||
68 | if not result then print(error_msg .. " " .. i) end | ||
69 | end | ||
70 | end | ||
71 | |||
72 | print("Sent " .. messages .. " messages totalling " .. length .. " bytes. The largest message was " .. #message .. " bytes.") | ||
73 | ]=] | ||
74 | |||
75 | mainProc = string.format(mainProc, count) | ||
76 | result, error_msg = luaproc.newproc(mainProc) | ||
77 | if not result then print(error_msg) end | ||
78 | |||
79 | luaproc.exit() | ||
80 | |||