šŸ† Luau Showcase

Show off your Luau creations!
Script Efficiency Test
This script was based on Xaviar Czervik's & Strife Onizuka's work , which I've modified it for my own purposes over the years, and now has been recreated for LUAU. Place your line of codes in the "Test Zone" and store any local variables if needed. --- Ignore this section --- function time(stamp) return tonumber(string.sub(stamp, 15, 16)) * 60000 + math.floor((tonumber(string.sub(stamp, 18, -2)) * 1000000.0) / 1000.0) end ts0 = "" ts1 = "" function state_entry() end function touch_start(num_detected) local i = 0 local max = 1000 ---Place your local variables here to prep the stage.--- local Data = "Aacon, Bacon, Cacon, Dacon, Eacon, Facon, Gacon, Hacon, Iacon, Jacon, Kacon, Lacon, Macon" ------------------------------------------- --- Ignore this section --- ts0 = ll.GetTimestamp() repeat -- TEST ZONE --------------------------------------------- local ListData = ll.CSV2List(Data) -- End of Test ------------------------------------------- --- Ignore this section below --- i = i + 1 until i >= max ts1 = ll.GetTimestamp() local elapsed = (time(ts1) - time(ts0)) / max ll.OwnerSay("Average Time:" .. tostring(elapsed) .. " milliseconds.") end state_entry() For those wondering why I've made these changes... I removed the framework time calculation because testing showed it was insignificant when exposed to many different elements in a sim that never be truly empty and free of other scripts. Background noise in the simulator can often be greater than FOR loopā€™s own execution time. LSLā€™s loop overhead is negligible or often unmeasurable due to the serverā€™s frame rounding. Since not all frames are treated the same, subtracting the framework time from it doesn't provide benefit. It's possible for test code to be smaller when ran on a good frames plus getting a few server rounding, and then have the basic FOR loop counting performs on the worst frames after. Rather not have that contaminates the result. I also changed how the time() function processes timestamps. Instead of handling the timestamp before and during the test, the script now stores the raw timestamps first, runs the test immediately, store the second timestamp as it finishes, and then processes the timestamp afterward. This ensures minimal interference and keeps string handling out of the test scope. Additionally, I reduced the iteration count from 10,000 to 1,000 since higher counts provided no meaningful improvement in averaging results; just redundant computation.
0
Table 2 Json And Json 2 Table (Mostly for debugging) with pretty print
Table 2 Json A quick and dirty method for dumping a table into a string function table2json(tbl,depth) if depth == true then depth = 1 end local set = {} local obj = false; local frst = 0 for k,v in pairs(tbl) do if k ~= (frst + 1) then obj = true break end frst = frst + 1 end for k , v in pairs(tbl) do local t = type(v) if t == "number" then v = `{v}` elseif v == nil then v = `null` elseif t == "table" then v = table2json(v,depth and depth+1 or false) elseif t == "function" then v = `"function<{debug.info(v,"n")}>"` else v = `"{v}"` end if obj then v = `"{k}":{v}` end set[#set+1] = v end local sep = "," if obj then if depth then sep = ",\n" sep = sep .. string.rep(" ",depth*2) set = sep:sub(2) .. table.concat(set,sep) .. sep:sub(2,#sep - 4) else set = table.concat(set,sep) end return `\{{set}\}` end return `[{table.concat(set,sep)}]` end can be called like this local tbl = {`a`,2,uuid("677bf9a4-bba5-4cf9-a4ad-4802a0f7ef46"),{`b`,`c`,{`d`,`e`,vector(1,1,1)}},a=`7`,{x=1,y=2,z=3},ll.Say} ll.OwnerSay(table2json(tbl)) ll.OwnerSay(table2json(tbl,true)) passing true or a number into the second argument enables indentation / pretty print Json 2 Table a crude v1 of json 2 table local function json2table(json) local tb = ll.Json2List(json) for k,v in pairs(tb) do if type(v) == "string" then local t = ll.JsonValueType(v,{}); if t == utf8.char(0xFDD2) then tb[k] = json2table(v) elseif t == utf8.char(0xFDD1) then local obj = json2table(v) v = {} for i = 1, #obj, 2 do v[obj[i]] = obj[i+1] end tb[k] = v end end end return tb end
1