repo
stringclasses
341 values
file_path
stringlengths
29
173
language
stringclasses
2 values
file_type
stringclasses
4 values
code
stringlengths
2
1.66M
tokens
int64
2
598k
Roblox/dash
Roblox-dash-5a885be/src/throttle.lua
luau
.lua
local Dash = script.Parent local assign = require(Dash.assign) type ThrottleOptions = { leading: boolean?, trailing: boolean?, } type ThrottleOptionsInternal = { leading: boolean, trailing: boolean, } -- `& (...any) -> ...any` in the function type is a funky way to mimick `T extends function` type AnyVoidFunctio...
912
Roblox/dash
Roblox-dash-5a885be/src/union.lua
luau
.lua
local Dash = script.Parent local None = require(Dash.None) local Types = require(Dash.Types) --[=[ Returns a new Map by merging all keys in the two Maps in left-to-right order. The `None` symbol can be used to remove existing elements. @param map1 The first Map to union @param map2 The second Map to union @retu...
162
Roblox/dash
Roblox-dash-5a885be/src/values.lua
luau
.lua
local Dash = script.Parent local Types = require(Dash.Types) local insert = table.insert --[=[ Returns an array of the values in the _input_ table. If the input is an array, ordering is preserved. If the input is a Map, elements are returned in an arbitrary order. @param input The table to extract values from. ...
122
Roblox/dash
Roblox-dash-5a885be/src/zip.lua
luau
.lua
--[=[ Returns an iterator over two given arrays that produces pairs of elements with the same index from both arrays. The iterator stops when the shortest array ends, i.e. when it encounters nil in one of the arrays. @param array1 The first array to zip. @param array2 The second array to zip. @return An iterator...
188
Roblox/dash
Roblox-dash-5a885be/suites/jest-bench.config.lua
luau
.lua
return { displayName = "Dash", testMatch = { "**/benchmark/*.bench", }, }
24
Roblox/dash
Roblox-dash-5a885be/suites/jest-test.config.lua
luau
.lua
return { displayName = "Dash", testMatch = { "**/tests/*.spec", }, }
24
Roblox/dash
Roblox-dash-5a885be/suites/run-tests.lua
luau
.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage") local processServiceExists, ProcessService = pcall(function() return game:GetService("ProcessService") end) local Packages = ReplicatedStorage:FindFirstChild("Packages") if not Packages or not Packages:FindFirstChild("Dev") then game:GetService("TestServ...
234
Roblox/dash
Roblox-dash-5a885be/tests/customMatchers.lua
luau
.lua
-- Checks that toString represenation of the error includes given message local function toThrowWithMessage(_, received, errorMessage) local ok, error = pcall(received) local pass = not ok and string.find(error:toString(), errorMessage) ~= nil local message if pass then message = function() return `expected {e...
130
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/Types.luau
luau
.luau
export type PNG = { width: number, height: number, pixels: buffer, readPixel: (x: number, y: number) -> (number, number, number, number), } export type Chunk = { type: string, offset: number, length: number, } export type IHDRChunk = { width: number, height: number, bitDepth: number, colorType: number, in...
159
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/chunks/IHDR.luau
luau
.luau
local Types = require("../Types") local COLOR_TYPE_BIT_DEPTH = { [0] = { 1, 2, 4, 8, 16 }, [2] = { 8, 16 }, [3] = { 1, 2, 4, 8 }, [4] = { 8, 16 }, [6] = { 8, 16 }, } local function read(buf: buffer, chunk: Types.Chunk): Types.IHDRChunk assert(chunk.length == 13, "IHDR data must be 13 bytes") local offset = ch...
398
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/chunks/PLTE.luau
luau
.luau
local Types = require("../Types") local function read(buf: buffer, chunk: Types.Chunk, header: Types.IHDRChunk): Types.PLTEChunk assert(chunk.length % 3 == 0, "malformed PLTE chunk") local count = chunk.length / 3 assert(count > 0, "no entries in PLTE") assert(count <= 256, "too many entries in PLTE") assert(cou...
206
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/chunks/init.luau
luau
.luau
return { IHDR = require("@self/IHDR"), PLTE = require("@self/PLTE"), tRNS = require("@self/tRNS"), }
34
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/chunks/tRNS.luau
luau
.luau
local Types = require("../Types") local function readU16(buf: buffer, offset: number, depth: number) return bit32.extract( bit32.bor(bit32.lshift(buffer.readu8(buf, offset), 8), buffer.readu8(buf, offset + 1)), 0, depth ) end local function read( buf: buffer, chunk: Types.Chunk, header: Types.IHDRChunk, p...
379
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/crc32.luau
luau
.luau
--!native --!optimize 2 -- stylua: ignore local lookup = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DD...
2,337
sircfenner/png-luau
sircfenner-png-luau-d9f8f3b/src/zlib.luau
luau
.luau
--!native --!optimize 2 local MAX_BITS = 15 -- stylua: ignore local LIT_LEN = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258 } -- stylua: ignore local LIT_EXTRA = { 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, } -- stylua: ign...
5,577
dphfox/tiniest
dphfox-tiniest-ba9d9ef/src/tiniest.luau
luau
.luau
-- From dphfox/tiniest, licenced under BSD --!strict local tiniest_plugin = require("./tiniest_plugin") type Context = DescribeContext | RunContext type DescribeContext = { type: "describe", labels: {string}, add_test: (Test) -> () } type RunContext = { type: "run" } export type ErrorReport = { type: "tiniest...
1,404
dphfox/tiniest
dphfox-tiniest-ba9d9ef/src/tiniest_expect.luau
luau
.luau
-- From dphfox/tiniest, licenced under BSD --!strict local tiniest_quote = require("./tiniest_quote") local tiniest_expect = {} type Context = { target: unknown, test: string, params: {unknown} } local context: Context = { target = nil, test = "", params = {} } local function fail( message: string? ): never...
1,098
dphfox/tiniest
dphfox-tiniest-ba9d9ef/src/tiniest_for_roblox.luau
luau
.luau
-- From dphfox/tiniest, licenced under BSD --!strict local tiniest_expect = require("./tiniest_expect") local tiniest_time = require("./tiniest_time") local tiniest_pretty = require("./tiniest_pretty") local tiniest = require("./tiniest") export type Options = { snapshot_path: string?, save_snapshots: boolean?, pr...
665
dphfox/tiniest
dphfox-tiniest-ba9d9ef/src/tiniest_quote.luau
luau
.luau
-- From dphfox/tiniest, licenced under BSD --!strict local function tiniest_quote( x: unknown, given_indent_amount: number? ): string if type(x) == "nil" or type(x) == "number" or type(x) == "boolean" or type(x) == "userdata" then return tostring(x) elseif type(x) == "string" then return string.fo...
378
dphfox/tiniest
dphfox-tiniest-ba9d9ef/src/tiniest_snapshot.luau
luau
.luau
-- From dphfox/tiniest, licensed under BSD3 --!strict local tiniest_quote = require("./tiniest_quote") local tiniest = require("./tiniest") type Test = tiniest.Test export type TestRunResult = tiniest.TestRunResult & { num_snapshots_updated: number, num_snapshots_obsolete: number } export type RunResult = tiniest.R...
1,293
luau-lang/lute
luau-lang-lute-7dab7df/.config.luau
luau
.luau
return { luau = { languagemode = "strict", lint = { ["*"] = true }, linterrors = true, aliases = { commands = "./lute/cli/commands", lute = "./definitions", std = "./lute/std/libs", }, }, lute = { lint = { ignores = { "**/*.d.luau", "**/*.snap.luau" }, }, }, }
105
luau-lang/lute
luau-lang-lute-7dab7df/.lute/bootstrap.luau
luau
.luau
--!strict local process = require("@lute/process") -- LUAUFIX: should `...` actually have the type `string...` for command-line environments local args: { [number]: string, n: number } = table.pack(...) :: any local cmd: { string } = { "tools/bootstrap.sh", table.unpack(args, 2, args.n) } local result = process.run...
100
luau-lang/lute
luau-lang-lute-7dab7df/.lute/luthier.luau
luau
.luau
--!strict local process = require("@lute/process") -- LUAUFIX: should `...` actually have the type `string...` for command-line environments local args: { [number]: string, n: number } = table.pack(...) :: any local cmd: { string } = { process.execPath(), "tools/luthier.luau", table.unpack(args, 2, args.n) } local ...
107
luau-lang/lute
luau-lang-lute-7dab7df/batteries/base64.luau
luau
.luau
--!optimize 2 --!strict local BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" local BASE64_ENCODING_LUT = table.create(4096) :: { number } local BASE64_DECODING_LUT = buffer.create(256) do for i = 0, 4095 do local hi = bit32.rshift(i, 6) + 1 local lo = bit32.band(i, 0x3F) + 1...
1,514
luau-lang/lute
luau-lang-lute-7dab7df/batteries/cli.luau
luau
.luau
local cli = {} cli.__index = cli type ArgKind = "positional" | "flag" | "option" | "variadic" type ArgOptions = { help: string?, aliases: { string }?, default: string?, required: boolean?, hidden: boolean?, } type ArgData = { name: string, kind: ArgKind, options: ArgOptions, } type ParseResult = { values: {...
1,563
luau-lang/lute
luau-lang-lute-7dab7df/batteries/collections/deque.luau
luau
.luau
type DequeData<T> = { _head: number, _tail: number, _values: { [number]: T }, } local deque = {} export type Deque<T> = setmetatable<DequeData<T>, typeof(deque)> deque.__index = deque deque.__len = function<T>(self: Deque<T>) return self._tail - self._head + 1 end local dequeLib = {} function dequeLib.new<T>(i...
422
luau-lang/lute
luau-lang-lute-7dab7df/batteries/difftext/init.luau
luau
.luau
local myersdiff = require("@self/myersdiff") local printdiff = require("@self/printdiff") local types = require("@self/types") export type diff = types.diff export type diffoptions = types.diffoptions local function diff(a: string, b: string, options: diffoptions): diff if options and options.byChar then return my...
124
luau-lang/lute
luau-lang-lute-7dab7df/batteries/difftext/myersdiff.luau
luau
.luau
local deque = require("@batteries/collections/deque") local tableext = require("@std/tableext") local types = require("./types") type diffoperation = types.diffoperation type diff = types.diff type EditGraphNode = { x: number, y: number, prev: EditGraphNode?, } local function editGraphNode(x: number, y: number, p...
1,287
luau-lang/lute
luau-lang-lute-7dab7df/batteries/difftext/printdiff.luau
luau
.luau
local richterm = require("@batteries/richterm") local myersdiff = require("./myersdiff") local myersdiffbychar = myersdiff.myersdiffbychar local myersdiffbyline = myersdiff.myersdiffbyline local types = require("./types") local brightGreen = richterm.brightGreen local brightRed = richterm.brightRed local bgGreen = rich...
1,799
luau-lang/lute
luau-lang-lute-7dab7df/batteries/difftext/types.luau
luau
.luau
export type diffoperationkey = "EQUAL" | "ADD" | "DELETE" export type diffoperation = { key: diffoperationkey, text: string, } export type diff = { diffoperation } export type diffoptions = { byChar: boolean?, }? return table.freeze({})
61
luau-lang/lute
luau-lang-lute-7dab7df/batteries/glob.luau
luau
.luau
--[[ Glob pattern matching and filesystem discovery. `glob.match(pattern, input)` tests whether a path matches a glob pattern. `glob.discover(pattern)` walks the filesystem returning all matching `Path`s. The implementation follows the Rust glob crate. The rules are: - `?` matches any single char...
1,758
luau-lang/lute
luau-lang-lute-7dab7df/batteries/pp.luau
luau
.luau
type ExistingOptions = { rawStrings: boolean?, } local isPrimitiveType = { string = true, number = true, boolean = true } local typeSortOrder: { [string]: number } = { ["boolean"] = 1, ["number"] = 2, ["string"] = 3, ["function"] = 4, ["vector"] = 5, ["buffer"] = 6, ["thread"] = 7, ["table"] = 8, ["userdata...
1,226
luau-lang/lute
luau-lang-lute-7dab7df/batteries/result.luau
luau
.luau
type T<Value> = | { success: true, value: Value } | { success: false, traceback: string, err: string } local result = {} function result.ok<Value>(value: Value): T<Value> return { success = true, value = value, } end function result.fail<Value>(err: string): T<Value> -- Ignore the current call to debug.traceb...
192
luau-lang/lute
luau-lang-lute-7dab7df/batteries/richterm.luau
luau
.luau
--[[ richterm terminal ansi formatter ]] export type Formatter = (s: string, nocolor: boolean?) -> string -- @noinline (if it ever exists) local function format(s: string, open: string, close: string, replace: string): string local index = string.find(s, close, #open + 1, true) local middle = s if index then ...
1,177
luau-lang/lute
luau-lang-lute-7dab7df/definitions/crypto.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local crypto = {} export type Hash<T> = { __hash: T } crypto.hash = table.freeze({ md5 = {} :: Hash<"md5">, sha1 = {} :: Hash<"sha1">, sha256 = {} :: Hash<"sha256">, sha512 = {} :: Hash<"sha512">, blake2b256 = {} :: Hash<"blake2b256">, }) --- Computes a cryptographic ...
396
luau-lang/lute
luau-lang-lute-7dab7df/definitions/fs.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local time = require("./time") local fs = {} --- An open file handle returned by `fs.open`. export type FileHandle = { fd: number, err: number, } --- The type of a filesystem entry: --- - `"file"`: A regular file. --- - `"dir"`: A directory. --- - `"link"`: A symbolic li...
1,232
luau-lang/lute
luau-lang-lute-7dab7df/definitions/luau.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local luau = {} --- Compiled Luau bytecode produced by `luau.compile`. export type Bytecode = { bytecode: string } --- Compiles Luau `source` to bytecode. function luau.compile(source: string): Bytecode error("not implemented") end --- Loads `bytecode` into a callable fu...
646
luau-lang/lute
luau-lang-lute-7dab7df/definitions/process.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) --- How a child process's standard streams should be handled: --- - `"default"`: Capture stdout and stderr to pipes, accessible via `ProcessResult`. --- - `"inherit"`: Pass the parent process's stdio streams through to the child. --- - `"none"`: Discard the child's stdio stre...
885
luau-lang/lute
luau-lang-lute-7dab7df/definitions/syntax/parser.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local cst = require("./cst") local parser = {} --- Parses `source` as a Luau script and returns the resulting CST. function parser.parse(source: string): cst.CstParseResult error("not implemented") end --- Parses `source` as a single Luau expression and returns the result...
100
luau-lang/lute
luau-lang-lute-7dab7df/definitions/system.luau
luau
.luau
--- CPU information for a single logical processor, including model, speed, and time-usage breakdown. export type CpuInfo = { model: string, speed: number, times: { sys: number, idle: number, irq: number, nice: number, user: number, }, } local system = {} --- Returns the number of logical CPU threads a...
316
luau-lang/lute
luau-lang-lute-7dab7df/definitions/task.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local time = require("./time") local task = {} --- Schedules `routine` to run immediately on the next resumption cycle, passing any additional arguments to it. Returns the thread. function task.spawn<T..., U...>(routine: ((T...) -> U...) | thread, ...: T...): thread error(...
324
luau-lang/lute
luau-lang-lute-7dab7df/definitions/time.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local time = {} local duration_ops = {} local instant = {} --- Returns the current time as an `Instant`. function time.now(): Instant error("not implemented") end --- Returns the number of seconds elapsed since `instant`. function time.since(instant: Instant): number err...
856
luau-lang/lute
luau-lang-lute-7dab7df/definitions/vm.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) local vm = {} --- Creates a new Luau VM from the module at `path` and returns its exported table. function vm.create(path: string): { [any]: any } error("not implemented") end return vm
58
luau-lang/lute
luau-lang-lute-7dab7df/docs/docgen.luau
luau
.luau
return { ["../lute/std/libs"] = { alias = "std", destination = "std" }, ["../definitions"] = { alias = "lute", destination = "lute" }, }
44
luau-lang/lute
luau-lang-lute-7dab7df/examples/a.luau
luau
.luau
local _ = require("./b")
7
luau-lang/lute
luau-lang-lute-7dab7df/examples/b.luau
luau
.luau
print("hello there") return {}
7
luau-lang/lute
luau-lang-lute-7dab7df/examples/cliargs.luau
luau
.luau
local cli = require("@batteries/cli") local args = cli.parser() args:add("input", "positional", { help = "Input file" }) args:add("verbose", "flag", { help = "Enable verbose mode", aliases = { "v" } }) args:add("output", "option", { help = "Output file", aliases = { "o" }, default = "default.txt" }) args:parse({ ......
136
luau-lang/lute
luau-lang-lute-7dab7df/examples/colorful.luau
luau
.luau
local richterm = require("@batteries/richterm") print(richterm.red("This is red text!")) print(richterm.bgRed("This is red background!")) print(richterm.bold("This is bold text!")) print(richterm.underline("This is underlined text!")) print(richterm.dim(richterm.italic("This is dim italic text!"))) print(richterm.red...
129
luau-lang/lute
luau-lang-lute-7dab7df/examples/compile.luau
luau
.luau
local luau = require("@std/luau") local bytecode_container = luau.compile('return "Hello, world!"') print(`Bytecode is {#bytecode_container["bytecode"]} bytes long`) print(luau.load(bytecode_container)())
54
luau-lang/lute
luau-lang-lute-7dab7df/examples/create_directory.luau
luau
.luau
local fs = require("@std/fs") local path = require("@std/path") local system = require("@std/system") local tmpdir = system.tmpdir() local directory = path.join(tmpdir, "example_dir") fs.createDirectory(directory, { makeParents = true }) if fs.exists(directory) and fs.type(directory) == "dir" then print("Directory ...
118
luau-lang/lute
luau-lang-lute-7dab7df/examples/difftext.luau
luau
.luau
local difftext = require("@batteries/difftext") local richterm = require("@batteries/richterm") local src = [[ local originalVariable = 1 local same = 1 function doSomething() -- comment -- removed print(originalVariable * 2) end print() ]] local destination = [[ local newVariable = 2 local same = 1 functi...
230
luau-lang/lute
luau-lang-lute-7dab7df/examples/directories.luau
luau
.luau
local fs = require("@std/fs") for _, file in fs.listDirectory("./examples") do print(`Example {file.name} is a {file.type}`) end
35
luau-lang/lute
luau-lang-lute-7dab7df/examples/docs/test_module.luau
luau
.luau
-- lute-lint-global-ignore(unused_variable) -- This file creates a mock module called test_module with random mock functions and different types of comments to test the reference doc generator reference.luau -- See output documentation file generated in this folder `test_module.md` local test_module = {} --- Property...
299
luau-lang/lute
luau-lang-lute-7dab7df/examples/fib.luau
luau
.luau
local module = {} function module.fib(n: number) return if n <= 2 then 1 else module.fib(n - 1) + module.fib(n - 2) end function module.fibTable(t: { n: number }) return if t.n <= 2 then 1 else module.fibTable({ n = t.n - 1 }) + module.fibTable({ n = t.n - 2 }) end return module
96
luau-lang/lute
luau-lang-lute-7dab7df/examples/fs_metadata.luau
luau
.luau
local fs = require("@std/fs") local path = require("@std/path") local process = require("@std/process") local scriptPath = path.resolve(process.cwd(), process.args[1]) local metadata = fs.metadata(scriptPath) local created = metadata.created print(tostring(created))
57
luau-lang/lute
luau-lang-lute-7dab7df/examples/hash.luau
luau
.luau
local crypto = require("@lute/crypto") local base64 = require("@batteries/base64") local message = "Hello, world!" local digest = crypto.digest(crypto.hash.sha256, message) function hexify(digest) local hex = {} for i = 1, buffer.len(digest) do hex[i] = string.format("%02x", buffer.readu8(digest, i - 1)) end r...
127
luau-lang/lute
luau-lang-lute-7dab7df/examples/homedir_cwd.luau
luau
.luau
local process = require("@std/process") print(process.cwd(), process.homedir())
17
luau-lang/lute
luau-lang-lute-7dab7df/examples/json.luau
luau
.luau
local json = require("@std/json") local serialize = json.serialize({ hello = "world", }, true) print(serialize) local deserialized = json.deserialize([[{ "hello": "world" }]]) deserialized = assert(json.asObject(deserialized)) print(deserialized.hello)
60
luau-lang/lute
luau-lang-lute-7dab7df/examples/lints/almost_swapped.luau
luau
.luau
-- Check out lute/cli/commands/lint/rules for the default rules used by lute lint! local lintTypes = require("@lint") local path = require("@std/path") local query = require("@std/syntax/query") local syntax = require("@std/syntax") local utils = require("@std/syntax/utils") local name = "almost_swapped" local messag...
900
luau-lang/lute
luau-lang-lute-7dab7df/examples/lints/divide_by_zero.luau
luau
.luau
-- Check out lute/cli/commands/lint/rules for the default rules used by lute lint! local lintTypes = require("@lint") local path = require("@std/path") local query = require("@std/syntax/query") local syntax = require("@std/syntax") local utils = require("@std/syntax/utils") local name = "divide_by_zero" local messag...
324
luau-lang/lute
luau-lang-lute-7dab7df/examples/main.luau
luau
.luau
print("hello")
4
luau-lang/lute
luau-lang-lute-7dab7df/examples/module_return_type/get_module_return_type.luau
luau
.luau
local luau = require("@std/luau") local path = require("@std/path") local process = require("@std/process") local filePath = path.join(process.cwd(), "examples", "module_return_type", "mainmodule.luau") local returnType = luau.typeofModule(filePath) if not returnType then error("Failed to get module return type") en...
298
luau-lang/lute
luau-lang-lute-7dab7df/examples/module_return_type/mainmodule.luau
luau
.luau
local tableext = require("@std/tableext") local testFilter: { [string]: number } = { ["a"] = 1, } local module = {} function module.func1(a: number) return function(s: string): boolean return s == tostring(a) end end module.strings = tableext.map(testFilter, function(value) return tostring(value) end) module...
99
luau-lang/lute
luau-lang-lute-7dab7df/examples/net_example.luau
luau
.luau
local net = require("@std/net") local task = require("@std/task") local pp = require("@batteries/pp") print(net.request("https://en.wikipedia.org/").status) print(pp(net.request("https://en.wikipedia.org/").headers)) local start = os.clock() local results = {} local done = 0 task.spawn(function() results[1] = n...
213
luau-lang/lute
luau-lang-lute-7dab7df/examples/options_transformer.luau
luau
.luau
local query = require("@std/syntax/query") local syntax = require("@std/syntax") local syntax_utils = require("@std/syntax/utils") local transformTypes = require("@transform") return { options = { { kind = "string", name = "functionName", default = "math.isnan" }, }, transform = function(ctx: transformTypes.Cont...
202
luau-lang/lute
luau-lang-lute-7dab7df/examples/parallel_serve.luau
luau
.luau
local vm = require("@lute/vm") local task = require("@std/task") local threadCount = 8 for _ = 1, threadCount do task.spawn(vm.create("./parallel_serve_helper").serve) end print(`Created {threadCount} server threads`)
59
luau-lang/lute
luau-lang-lute-7dab7df/examples/parallel_serve_helper.luau
luau
.luau
local server = require("@lute/net/server") return { serve = function() server.serve({ handler = function(_) return "Hello, lute!" end, reuseport = true, }) end, }
52
luau-lang/lute
luau-lang-lute-7dab7df/examples/parallel_sort.luau
luau
.luau
local vm = require("@lute/vm") local task = require("@std/task") local function getslice(t, n: number, m: number) local size = math.ceil(#t / m) local slice = table.create(size) table.move(t, 1 + (n - 1) * size, n * size, 1, slice) return slice end local function merge<T>(t1: { T }, t2: { T }, comp: (T, T) -> l...
740
luau-lang/lute
luau-lang-lute-7dab7df/examples/parallel_sort_helper.luau
luau
.luau
return { sort = function(t) -- LUAUFIX - we cannot figure out the type of the array elements, even with an annotation on t. table.sort(t, function(a: number, b: number) return a < b end) return t end, }
62
luau-lang/lute
luau-lang-lute-7dab7df/examples/parsing.luau
luau
.luau
local syntax = require("@std/syntax") local pretty = require("@batteries/pp") local foo = syntax.parseExpr("5") print(pretty(foo))
33
luau-lang/lute
luau-lang-lute-7dab7df/examples/process.luau
luau
.luau
local process = require("@std/process") process.system("echo hello", {}) local result = process.run({ "echo", "Hello, lute!" }) print(result.exitcode) print(result.stdout) local r1 = process.run({ "echo", "-n", "One" }) local r2 = process.run({ "echo", "-n", "Two" }) local r3 = process.run({ "echo", "-n", "Three" }...
220
luau-lang/lute
luau-lang-lute-7dab7df/examples/process_env.luau
luau
.luau
local process = require("@std/process") print(process.env.HOME) print(process.env.LUTE_HOME) process.env.LUTE_HOME = "/home/lute" print(process.env.LUTE_HOME) for k, v in process.env do print(k, v) end
55
luau-lang/lute
luau-lang-lute-7dab7df/examples/profile_test.luau
luau
.luau
-- Test program for profiler with deep call stacks and recursion -- Fibonacci with recursion (creates deep stacks) local function fibonacci(n: number): number if n <= 1 then return n end return fibonacci(n - 1) + fibonacci(n - 2) end -- Array processing with nested calls local function processArray(arr: { number...
556
luau-lang/lute
luau-lang-lute-7dab7df/examples/pwhash.luau
luau
.luau
local crypto = require("@lute/crypto") local secret = "woof" local password = crypto.password.hash(secret) function hexify(digest) local hex = {} for i = 1, buffer.len(digest) do hex[i] = string.format("%02x", buffer.readu8(digest, i - 1)) end return table.concat(hex) end print(`password hash: {hexify(password...
124
luau-lang/lute
luau-lang-lute-7dab7df/examples/query.luau
luau
.luau
local syntax = require("@std/syntax") local query = require("@std/syntax/query") local utils = require("@std/syntax/utils") local cst = syntax.parseExpr("require(OldComponent)") local p = query.findAllFromRoot(cst, utils.isRequireCall):filter(function(call) local firstArg = call.arguments[1] return firstArg.tag == ...
136
luau-lang/lute
luau-lang-lute-7dab7df/examples/query_transformer.luau
luau
.luau
local query = require("@std/syntax/query") local syntax = require("@std/syntax") local syntax_utils = require("@std/syntax/utils") local transformTypes = require("@transform") local function transform(ctx: transformTypes.Context) return query .findAllFromRoot(ctx.parseresult :: syntax.CstParseResult, syntax_utils....
165
luau-lang/lute
luau-lang-lute-7dab7df/examples/secretbox.luau
luau
.luau
local crypto = require("@lute/crypto") local message = "Hello, world!" local box = crypto.secretbox.seal(message) function hexify(digest) local hex = {} for i = 1, buffer.len(digest) do hex[i] = string.format("%02x", buffer.readu8(digest, i - 1)) end return table.concat(hex) end print(hexify(box.ciphertext)) ...
124
luau-lang/lute
luau-lang-lute-7dab7df/examples/serve.luau
luau
.luau
local server = require("@lute/net/server") print("Starting server...") -- Start the server (non-blocking) local instance = server.serve(function(_) return "Hello, lute!" end) print(`Server listening on http://{instance.hostname}:{instance.port}`) print("Program ending, but server will continue running in the backg...
83
luau-lang/lute
luau-lang-lute-7dab7df/examples/spawn_example.luau
luau
.luau
local vm = require("@lute/vm") local task = require("@std/task") print("start") local vm1 = vm.create("./fib") local vm2 = vm.create("./fib") local vm3 = vm.create("./fib") print("fib(15):", vm1.fib(15)) print("fib(20):", vm2.fib(20)) print("done inline") do local start = os.clock() print("fib(10):", vm1.fib(10...
513
luau-lang/lute
luau-lang-lute-7dab7df/examples/system_environment_check.luau
luau
.luau
local system = require("@std/system") if system.win32 then print("Running on Windows") elseif system.linux then print("Running on Linux") elseif system.macos then print("Running on macOS") elseif system.unix then print("Running on Unix") else print("Unknown operating system") end
66
luau-lang/lute
luau-lang-lute-7dab7df/examples/system_lib.luau
luau
.luau
local system = require("@std/system") print( string.format( "%s (%s-%s) - %d cores, uptime for %ss | freemem: %dMB | totalmem: %dMB", system.hostName(), system.os, system.arch, system.threadCount(), tostring(system.uptime()), system.freeMemory(), system.totalMemory() ) ) for _i, _cpu in system.cpus(...
159
luau-lang/lute
luau-lang-lute-7dab7df/examples/task-delay.luau
luau
.luau
local task = require("@lute/task") task.delay(1, coroutine.create(print), vector.one) task.delay(1, print, vector.one)
31
luau-lang/lute
luau-lang-lute-7dab7df/examples/task-resume.luau
luau
.luau
local task = require("@lute/task") local c = coroutine.create(function() print("hello") -- We don't know what subsequent calls to coroutine.yield produce. print(coroutine.yield() :: any) print("wtf") end) task.resume(c) task.resume(c, "world", "meow for good measure") local _ = coroutine.running() task.spawn(pr...
88
luau-lang/lute
luau-lang-lute-7dab7df/examples/task-wait.luau
luau
.luau
local task = require("@lute/task") local time = require("@std/time") print(task.wait(1)) print(task.wait(time.duration.seconds(1))) print(task.wait()) -- while true do -- local start = time.now() -- local delta = task.wait(1) -- local stop = time.now() -- print(stop - start) -- print(delta) -- end
82
luau-lang/lute
luau-lang-lute-7dab7df/examples/testing.luau
luau
.luau
local test = require("@std/test") local runner = require("@std/test/runner") test.case("foo", function(assert) assert.eq(3, 3) assert.eq(6, 1) end) test.case("bar", function(assert) assert.eq("a", "b") end) test.case("baz", function(assert) assert.neq("a", "b") end) test.suite("MySuite", function(suite) -- bef...
446
luau-lang/lute
luau-lang-lute-7dab7df/examples/time_example.luau
luau
.luau
local time = require("@std/time") local duration = time.duration local fiveSeconds = duration.seconds(5) local tenSeconds = fiveSeconds * 2 local fifteenSeconds = fiveSeconds + tenSeconds print(fiveSeconds) print(tenSeconds) print(fifteenSeconds) print(fiveSeconds < tenSeconds) print(fifteenSeconds > tenSeconds) lo...
127
luau-lang/lute
luau-lang-lute-7dab7df/examples/time_instants.luau
luau
.luau
local time = require("@lute/time") local start = time.now() for _ = 1, 10000 do vector.dot(vector.one, vector.zero) end local stop = time.now() assert(stop > start) assert(stop ~= start) assert(start == start) print((stop - start):toMicroseconds())
67
luau-lang/lute
luau-lang-lute-7dab7df/examples/toml.luau
luau
.luau
local toml = require("@batteries/toml") local deserialized = toml.deserialize([=[ hello = "world" infinity = inf nan_value = nan escaped_string = "This is a string with a newline\ncharacter" [world] v1 = "hi" v2 = 8080 v3 = true [[users]] name = "Alice" age = 25 [[users]] name = "Bob" age = 30 [people.Tom] age = 3...
126
luau-lang/lute
luau-lang-lute-7dab7df/examples/transformee.luau
luau
.luau
local x = math.sqrt(-1) -- x ~= x should become math.isnan(x) local _b = x ~= x
26
luau-lang/lute
luau-lang-lute-7dab7df/examples/user_input_no_prompt.luau
luau
.luau
-- User input can be provided in multiple ways: -- 1. lute user_input.luau -- 2. echo "Hello!" | lute user_input_no_prompt.luau -- 3. lute user_input_no_prompt.luau < input_text.txt local io = require("@std/io") -- Get user input local input = io.input() print(input)
78
luau-lang/lute
luau-lang-lute-7dab7df/examples/user_input_with_prompt.luau
luau
.luau
-- User input can be provided in multiple ways: -- 1. lute user_input.luau -- 2. echo "Hello!" | lute user_input_with_prompt.luau -- 3. lute user_input_with_prompt.luau < input_text.txt local io = require("@std/io") -- Get user input with prompt local name = io.input("Please enter your name: ") print(name)
86
luau-lang/lute
luau-lang-lute-7dab7df/examples/walk_directory.luau
luau
.luau
local fslib = require("@std/fs") local path = require("@std/path") local system = require("@std/system") local tmpdir = system.tmpdir() local baseDir = path.join(tmpdir, "walk_directory_example") -- Setup: create a directory structure if not fslib.exists(baseDir) then fslib.createDirectory(baseDir, { makeParents = t...
268
luau-lang/lute
luau-lang-lute-7dab7df/examples/watch_directory.luau
luau
.luau
local fs = require("@std/fs") local path = require("@std/path") local system = require("@std/system") local task = require("@lute/task") -- Setup, get a temporary directory to watch local tmpdir = system.tmpdir() local watchedFileName = "watched.txt" local watched = path.join(tmpdir, watchedFileName) if fs.exists(wat...
232
luau-lang/lute
luau-lang-lute-7dab7df/examples/websocket_echo.luau
luau
.luau
local client = require("@lute/net/client") print("connecting to echo server...") local _ws: client.WebSocket? _ws = client.websocket("wss://echo.websocket.org", { onopen = function() print("websocket opened") if _ws then _ws:send("hello from lute over websockets") _ws:send(buffer.create(4)) _ws:send("cl...
207
luau-lang/lute
luau-lang-lute-7dab7df/examples/writeFile.luau
luau
.luau
local fs = require("@std/fs") -- Open a file if it doesn't exist, truncate it, local file = fs.open("dest", "w+") if file == nil then print("Error opening file") return end fs.write(file, "This is some other text") fs.close(file)
65
luau-lang/lute
luau-lang-lute-7dab7df/lute/cli/commands/debug/dapTypes.luau
luau
.luau
-- these types reflect our requirements for our implementation of DAP, not -- necessarily the actual DAP specification. For example, sources in DAP could have -- path be optional, but we enforce that it is required. export type Capability = { supportConfigurationDoneRequest: boolean, supportTerminateRequest: boolean...
169
luau-lang/lute
luau-lang-lute-7dab7df/lute/cli/commands/debug/init.luau
luau
.luau
local io = require("@std/io") local cli = require("@batteries/cli") local dap = require("@self/dap") local USAGE = "Usage: lute debug serve" local function printHelp() print(USAGE) print([[ Starts the Lute debugger as a DAP server. SUBCOMMANDS: serve Start a DAP debug adapter server over stdio ...
224
luau-lang/lute
luau-lang-lute-7dab7df/lute/cli/commands/lib/files.luau
luau
.luau
local fs = require("@lute/fs") local process = require("@lute/process") local ignore = require("./ignore") local path = require("@std/path") local stringext = require("@std/stringext") local tableext = require("@std/tableext") local function traverseDirectoryRecursive( directory: path.Path, ignoreResolver: ignore.I...
455
luau-lang/lute
luau-lang-lute-7dab7df/lute/cli/commands/lib/ignore.luau
luau
.luau
local fs = require("@std/fs") local path = require("@std/path") local parseIgnores = require("./parseIgnores") local isIgnored = parseIgnores.isIgnored local parseGitignore = parseIgnores.parseGitignore --- Performs ignore resolution on a set of local IgnoreResolver = {} IgnoreResolver.__index = IgnoreResolver type G...
623
luau-lang/lute
luau-lang-lute-7dab7df/lute/cli/commands/lib/parseIgnores.luau
luau
.luau
local fs = require("@std/fs") local path = require("@std/path") local stringext = require("@std/stringext") local system = require("@std/system") export type Glob = { pattern: string, onlyMatchDirectories: boolean, matchAnywhere: boolean } export type GitignoreData = { location: string, ignores: { Glob }, whitelis...
1,529