| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | mg.write("HTTP/1.0 200 OK\r\n")mg.write("Connection: close\r\n")mg.write("Cache-Control: no-cache, no-store, must-revalidate, max-age=0\r\n")mg.write("Content-Type: text/plain\r\n")mg.write("\r\n")if not shared then  mg.write("\"shared\" does not exist\n")  returnelseif type(shared) ~= "userdata" then  mg.write("\"shared\" is not userdata\n")  returnend-- Test with numbermg.write("\nNumber:\n")x = shared.countmg.write("Previous count was " .. tostring(x) .. " (type " .. type(x) .. ")\n")x = x or 0x = x + 1shared.count = xmg.write("Store new count " .. tostring(x) .. " (type " .. type(x) .. ")\n")x = shared.countmg.write("New count is " .. tostring(x) .. " (type " .. type(x) .. ")\n")-- Test with namemg.write("\nString:\n")x = shared.namemg.write("Previous name was " .. tostring(x) .. " (type " .. type(x) .. ")\n")x = x or ""l = string.len(x) % 26x = x .. string.char(string.byte("a") + l)shared.name = xmg.write("Store new name " .. tostring(x) .. " (type " .. type(x) .. ")\n")x = shared.namemg.write("New name is " .. tostring(x) .. " (type " .. type(x) .. ")\n")-- Test with booleanmg.write("\nBoolean:\n")x = shared.conditionmg.write("Previous condition was " .. tostring(x) .. " (type " .. type(x) .. ")\n")x = not xshared.condition = xmg.write("Store new condition " .. tostring(x) .. " (type " .. type(x) .. ")\n")x = shared.conditionmg.write("New condition is " .. tostring(x) .. " (type " .. type(x) .. ")\n")-- Test using "shared" as arraymg.write("\nArray element:\n")mg.write("Previous array was: ")for i=1,10 do  x = shared[i]  mg.write(tostring(x) .. " (" .. type(x):sub(1,1) .. ") ")endmg.write("\n")for i=1,10 do  shared[i] = shared[(i + 1) % 10 + 1] or iendmg.write("Shifted array is:   ")for i=1,10 do  x = shared[i]  mg.write(tostring(x) .. " (" .. type(x):sub(1,1) .. ") ")endmg.write("\n")-- Test using "shared" as arraymg.write("\nBoolean indexed element:\n")x = shared[true]y = shared[false]mg.write("Previous elements were "         .. tostring(x) .. " (type " .. type(x) .. ") / "         .. tostring(y) .. " (type " .. type(y) .. ")\n")x = not xy = not xshared[true] = xshared[false] = ymg.write("New elements are "         .. tostring(x) .. " (type " .. type(x) .. ") / "         .. tostring(y) .. " (type " .. type(y) .. ")\n")-- Check if experimental functions (starting with __) are availableif not shared.__inc then  mg.write("\nExperimental functions not available\n")  returnelse  mg.write("\nTesting experimental functions\n")end-- Test __inc/__dec functionsif not shared.x then  shared.x = 0  shared.y = 0endmg.write("__inc(x) = " .. shared.__inc("x") .. "\n")mg.write("__dec(y) = " .. shared.__dec("y") .. "\n")-- Test __add functionif not shared.x then  shared.x = 0  shared.y = 0endmg.write("__add(x, 10) = " .. shared.__add("x", 10) .. "\n")mg.write("__add(y, -10) = " .. shared.__add("y", -10) .. "\n")-- end
 |