1mg.write("HTTP/1.0 200 OK\r\n") 2mg.write("Connection: close\r\n") 3mg.write("Cache-Control: no-cache, no-store, must-revalidate, max-age=0\r\n") 4mg.write("Content-Type: text/plain\r\n") 5mg.write("\r\n") 6 7if not shared then 8 mg.write("\"shared\" does not exist\n") 9 return 10elseif type(shared) ~= "userdata" then 11 mg.write("\"shared\" is not userdata\n") 12 return 13end 14 15-- Test with number 16mg.write("\nNumber:\n") 17x = shared.count 18mg.write("Previous count was " .. tostring(x) .. " (type " .. type(x) .. ")\n") 19x = x or 0 20x = x + 1 21shared.count = x 22mg.write("Store new count " .. tostring(x) .. " (type " .. type(x) .. ")\n") 23x = shared.count 24mg.write("New count is " .. tostring(x) .. " (type " .. type(x) .. ")\n") 25 26-- Test with name 27mg.write("\nString:\n") 28x = shared.name 29mg.write("Previous name was " .. tostring(x) .. " (type " .. type(x) .. ")\n") 30x = x or "" 31l = string.len(x) % 26 32x = x .. string.char(string.byte("a") + l) 33shared.name = x 34mg.write("Store new name " .. tostring(x) .. " (type " .. type(x) .. ")\n") 35x = shared.name 36mg.write("New name is " .. tostring(x) .. " (type " .. type(x) .. ")\n") 37 38 39-- Test with boolean 40mg.write("\nBoolean:\n") 41x = shared.condition 42mg.write("Previous condition was " .. tostring(x) .. " (type " .. type(x) .. ")\n") 43x = not x 44shared.condition = x 45mg.write("Store new condition " .. tostring(x) .. " (type " .. type(x) .. ")\n") 46x = shared.condition 47mg.write("New condition is " .. tostring(x) .. " (type " .. type(x) .. ")\n") 48 49 50-- Test using "shared" as array 51mg.write("\nArray element:\n") 52mg.write("Previous array was: ") 53for i=1,10 do 54 x = shared[i] 55 mg.write(tostring(x) .. " (" .. type(x):sub(1,1) .. ") ") 56end 57mg.write("\n") 58for i=1,10 do 59 shared[i] = shared[(i + 1) % 10 + 1] or i 60end 61mg.write("Shifted array is: ") 62for i=1,10 do 63 x = shared[i] 64 mg.write(tostring(x) .. " (" .. type(x):sub(1,1) .. ") ") 65end 66mg.write("\n") 67 68 69-- Test using "shared" as array 70mg.write("\nBoolean indexed element:\n") 71x = shared[true] 72y = shared[false] 73mg.write("Previous elements were " 74 .. tostring(x) .. " (type " .. type(x) .. ") / " 75 .. tostring(y) .. " (type " .. type(y) .. ")\n") 76x = not x 77y = not x 78shared[true] = x 79shared[false] = y 80mg.write("New elements are " 81 .. tostring(x) .. " (type " .. type(x) .. ") / " 82 .. tostring(y) .. " (type " .. type(y) .. ")\n") 83 84 85-- Check if experimental functions (starting with __) are available 86if not shared.__inc then 87 mg.write("\nExperimental functions not available\n") 88 return 89else 90 mg.write("\nTesting experimental functions\n") 91end 92 93 94-- Test __inc/__dec functions 95if not shared.x then 96 shared.x = 0 97 shared.y = 0 98end 99mg.write("__inc(x) = " .. shared.__inc("x") .. "\n") 100mg.write("__dec(y) = " .. shared.__dec("y") .. "\n") 101 102 103-- Test __add function 104if not shared.x then 105 shared.x = 0 106 shared.y = 0 107end 108mg.write("__add(x, 10) = " .. shared.__add("x", 10) .. "\n") 109mg.write("__add(y, -10) = " .. shared.__add("y", -10) .. "\n") 110 111 112-- end 113