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/cryo | Roblox-cryo-1514eab/src/Dictionary/init.lua | luau | .lua | --[[
Defines utilities for working with 'dictionary-like' tables.
Dictionaries can be indexed by any value, but don't have the ordering
expectations that lists have.
]]
return {
equals = require(script.equals),
filter = require(script.filter),
join = require(script.join),
keys = require(script.keys),
map = re... | 92 |
Roblox/cryo | Roblox-cryo-1514eab/src/Dictionary/join.lua | luau | .lua | local None = require(script.Parent.Parent.None)
--[[
Combine a number of dictionary-like tables into a new table.
Keys specified in later tables will overwrite keys in previous tables.
Use `Cryo.None` as a value to remove a key. This is necessary because
Lua does not distinguish between a value not being present... | 235 |
Roblox/cryo | Roblox-cryo-1514eab/src/Dictionary/keys.lua | luau | .lua | --[[
Returns a list of the keys from the given dictionary.
]]
local function keys(dictionary)
local new = {}
local index = 1
for key in pairs(dictionary) do
new[index] = key
index = index + 1
end
return new
end
return keys
| 62 |
Roblox/cryo | Roblox-cryo-1514eab/src/Dictionary/map.lua | luau | .lua | --!strict
--[=[
Returns a new Dictionary with keys and values passed through a mapper function.
Returning a second value in the mapper function will reassign the key.
]=]
local function map<K, V, K2, V2>(collection: { [K]: V }, mapper: (V, K) -> (V2, K2?)): { [K2]: V2 }
local new = {}
for key, value in collectio... | 161 |
Roblox/cryo | Roblox-cryo-1514eab/src/Dictionary/omit.lua | luau | .lua | --!strict
--[=[
Returns a Dictionary which excludes the given `keys`.
]=]
local function omit<K, V>(dictionary: { [K]: V }, ...: K): { [K]: V }
local new = table.clone(dictionary)
for _, key in { ... } do
new[key] = nil
end
return new
end
return omit
| 76 |
Roblox/cryo | Roblox-cryo-1514eab/src/Dictionary/union.lua | luau | .lua | --!strict
local function union<T, U>(dictionary1: T, dictionary2: U): T & U
local new: any = table.clone(dictionary1 :: any)
for key, value in dictionary2 :: any do
new[key] = value
end
return new
end
return union
| 65 |
Roblox/cryo | Roblox-cryo-1514eab/src/Dictionary/values.lua | luau | .lua | --[[
Returns a list of the values of the given dictionary.
]]
local function values(dictionary)
local new = {}
local index = 1
for _, value in pairs(dictionary) do
new[index] = value
index = index + 1
end
return new
end
return values
| 63 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/equals.lua | luau | .lua | local equalObjects = require(script.Parent.Parent.equalObjects)
local function compare(a, b)
if type(a) ~= "table" or type(b) ~= "table" then
return a == b
end
if #a ~= #b then
return false
end
for i = 1, #a do
if a[i] ~= b[i] then
return false
end
end
return true
end
local function equals<T>(...... | 180 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/filter.lua | luau | .lua | --[[
Create a copy of a list with only values for which `callback` returns true.
Calls the callback with (value, index).
]]
local function filter(list, callback)
local new = {}
local index = 1
for i = 1, #list do
local value = list[i]
if callback(value, i) then
new[index] = value
index = index + 1
end... | 101 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/filterMap.lua | luau | .lua | --[[
Create a copy of a list doing a combination filter and map.
If callback returns nil for any item, it is considered filtered from the
list. Any other value is considered the result of the 'map' operation.
]]
local function filterMap(list, callback)
local new = {}
local index = 1
for i = 1, #list do
local ... | 121 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/find.lua | luau | .lua | --[[
Returns the index of the first value found or nil if not found.
]]
local function find(list, value)
for i = 1, #list do
if list[i] == value then
return i
end
end
return nil
end
return find
| 60 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/findWhere.lua | luau | .lua | --[[
Returns the index of the first value for which predicate(value, index) is truthy, or nil if not found.
]]
local function findWhere(list, predicate)
for i = 1, #list do
if predicate(list[i], i) then
return i
end
end
return nil
end
return findWhere
| 73 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/foldLeft.lua | luau | .lua | --[[
Performs a left-fold of the list with the given initial value and callback.
]]
local function foldLeft(list, callback, initialValue)
local accum = initialValue
for i = 1, #list do
accum = callback(accum, list[i], i)
end
return accum
end
return foldLeft
| 69 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/foldRight.lua | luau | .lua | --[[
Performs a right-fold of the list with the given initial value and callback.
]]
local function foldRight(list, callback, initialValue)
local accum = initialValue
for i = #list, 1, -1 do
accum = callback(accum, list[i], i)
end
return accum
end
return foldRight
| 72 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/getRange.lua | luau | .lua | --[[
Returns a new list containing only the elements within the given range.
]]
local function getRange(list, startIndex, endIndex)
assert(startIndex <= endIndex, "startIndex must be less than or equal to endIndex")
local new = {}
local index = 1
for i = math.max(1, startIndex), math.min(#list, endIndex) do
n... | 99 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/init.lua | luau | .lua | --[[
Defines utilities for working with 'list-like' tables.
]]
return {
equals = require(script.equals),
filter = require(script.filter),
filterMap = require(script.filterMap),
find = require(script.find),
findWhere = require(script.findWhere),
foldLeft = require(script.foldLeft),
foldRight = require(script.fo... | 146 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/join.lua | luau | .lua | local None = require(script.Parent.Parent.None)
--[[
Joins any number of lists together into a new list
]]
local function join(...)
local new = {}
for listKey = 1, select("#", ...) do
local list = select(listKey, ...)
local len = #new
for itemKey = 1, #list do
if list[itemKey] == None then
len = len ... | 122 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/map.lua | luau | .lua | --[[
Create a copy of a list where each value is transformed by `callback`
]]
local function map(list, callback)
local new = {}
for i = 1, #list do
new[i] = callback(list[i], i)
end
return new
end
return map
| 60 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/removeIndex.lua | luau | .lua | --[[
Remove the element at the given index.
]]
local function removeIndex(list, index)
local new = {}
local removed = 0
for i = 1, #list do
if i == index then
removed = 1
else
new[i - removed] = list[i]
end
end
return new
end
return removeIndex
| 81 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/removeRange.lua | luau | .lua | --[[
Remove the range from the list starting from the index.
]]
local function removeRange(list, startIndex, endIndex)
assert(startIndex <= endIndex, "startIndex must be less than or equal to endIndex")
local new = {}
local index = 1
for i = 1, math.min(#list, startIndex - 1) do
new[index] = list[i]
index = ... | 127 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/removeValue.lua | luau | .lua | --[[
Creates a new list that has no occurrences of the given value.
]]
local function removeValue(list, value)
local new = {}
local index = 1
for i = 1, #list do
if list[i] ~= value then
new[index] = list[i]
index = index + 1
end
end
return new
end
return removeValue
| 85 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/replaceIndex.lua | luau | .lua | --[[
Returns a new list with the new value replaced at the given index.
]]
local function replaceIndex(list, index, value)
local new = {}
local len = #list
assert(index <= len, "index must be less or equal than the list length")
for i = 1, len do
if i == index then
new[i] = value
else
new[i] = list[i]... | 102 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/reverse.lua | luau | .lua | --[[
Returns a new list with the reversed order of the given list
]]
local function reverse(list)
local new = {}
local len = #list
local top = len + 1
for i = 1, len do
new[i] = list[top - i]
end
return new
end
return reverse
| 68 |
Roblox/cryo | Roblox-cryo-1514eab/src/List/sort.lua | luau | .lua | --[[
Returns a new list, ordered with the given sort callback.
If no callback is given, the default table.sort will be used.
]]
local function sort(list, callback)
local new = {}
for i = 1, #list do
new[i] = list[i]
end
table.sort(new, callback)
return new
end
return sort
| 74 |
Roblox/cryo | Roblox-cryo-1514eab/src/None.lua | luau | .lua | --[[
Represents a value that is intentionally present, but should be interpreted
as `nil`.
Cryo.None is used by included utilities to make removing values more
ergonomic.
]]
local None = newproxy(true)
getmetatable(None).__tostring = function()
return "Cryo.None"
end
return None
| 67 |
Roblox/cryo | Roblox-cryo-1514eab/src/equalObjects.lua | luau | .lua | --!strict
local function equalObjects(...)
local firstObject = select(1, ...)
for i = 2, select("#", ...) do
if firstObject ~= select(i, ...) then
return false
end
end
return true
end
return equalObjects
| 60 |
Roblox/cryo | Roblox-cryo-1514eab/src/equalsDeep.lua | luau | .lua | --!strict
local equalObjects = require(script.Parent.equalObjects)
local function compareDeep(a, b)
if type(a) ~= "table" or type(b) ~= "table" then
return a == b
end
for key, value in a do
if not compareDeep(b[key], value) then
return false
end
end
for key, value in b do
if not compareDeep(a[key], v... | 195 |
Roblox/cryo | Roblox-cryo-1514eab/src/init.lua | luau | .lua | return {
Dictionary = require(script.Dictionary),
List = require(script.List),
isEmpty = require(script.isEmpty),
None = require(script.None),
}
| 28 |
Roblox/cryo | Roblox-cryo-1514eab/src/isEmpty.lua | luau | .lua | local function isEmpty(object)
return next(object) == nil
end
return isEmpty
| 17 |
Roblox/cryo | Roblox-cryo-1514eab/tests/init.server.lua | luau | .lua | -- Lest chokes on .server.lua files so we pass the `spec` module to it and mount
-- this file in our project so we can run tests in Studio.
require(script.spec)
| 41 |
Roblox/cryo | Roblox-cryo-1514eab/tests/spec.lua | luau | .lua | local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TestEZ = require(ReplicatedStorage.Packages.Dev.TestEZ)
local results = TestEZ.TestBootstrap:run({
ReplicatedStorage.Packages.Cryo,
})
local success, ProcessService = pcall(game.GetService, game, "ProcessService")
if success and ProcessService the... | 96 |
ffrostfall/luausignal | ffrostfall-luausignal-ebed2c1/.lute/tests.luau | luau | .luau | local task = require("@lute/task")
task.spawn(function()
require("@tests/signal.spec")()
end)
| 23 |
ffrostfall/luausignal | ffrostfall-luausignal-ebed2c1/benches/collect.bench.luau | luau | .luau | --!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local signal = require(ReplicatedStorage.signal)
return {
Functions = {
["bit manip: construct collectors"] = function(Profiler: any)
local sig = signal()
Profiler.Begin("construct")
for i = 1, 31 do
sig:collect()
... | 430 |
ffrostfall/luausignal | ffrostfall-luausignal-ebed2c1/benches/libs/goodsignal.luau | luau | .luau | --!optimize 2
--!native
--------------------------------------------------------------------------------
-- Batched Yield-Safe Signal Implementation --
-- This is a Signal class which has effectively identical behavior to a --
-- normal RBXScriptSignal, with the only difference b... | 1,475 |
ffrostfall/luausignal | ffrostfall-luausignal-ebed2c1/benches/signal.bench.luau | luau | .luau | --!optimize 2
--!native
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local goodsignal = require(ReplicatedStorage.benches.libs.goodsignal)
local luausignal = require(ReplicatedStorage.signal)
return {
Functions = {
["luausignal constructor"] = function()
local _s
for i = 1, 500 do
_s =... | 663 |
ffrostfall/luausignal | ffrostfall-luausignal-ebed2c1/src/init.luau | luau | .luau | --!optimize 2
--!native
local task = task or require("@lute/task")
local tspawn = task.spawn
local NIL_TABLE = {}
local free_thread: thread? = nil
local function bitmask(idx: number)
return 2 ^ idx
end
local function set_bit(int: number, mask: number): number
return bit32.bor(int, mask)
end
local function get_bi... | 1,829 |
ffrostfall/luausignal | ffrostfall-luausignal-ebed2c1/vendor/testkit.luau | luau | .luau | --!nocheck
--!nolint
-------------------------------------------------------------------------------
-- testkit.luau
-- v0.7.3
--------------------------------------------------------------------------------
local color = {
white_underline = function(s: string)
return `\27[1;4m{s}\27[0m`
end,
white = function(s... | 2,781 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/init.luau | luau | .luau | --!native
--!optimize 2
-- stylua: ignore
local HEX_TO_BINARY = {
["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011",
["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111",
["8"] = "1000", ["9"] = "1001", ["a"] = "1010", ["b"] = "1011",
["c"] = "1100", ["d"] = "1101", ["e"] = "1110... | 6,996 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/lune/verify-package.luau | luau | .luau | local fs = require("@lune/fs")
local serde = require("@lune/serde")
local wally = serde.decode("toml", fs.readFile("wally.toml"))
local npm = serde.decode("json", fs.readFile("package.json"))
local wally_name = wally.package.name
local npm_name = string.match(npm.name, "^@(%w+/%w+)$")
assert(npm_name == wally_name, "... | 420 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/test.luau | luau | .luau | local t1 = os.clock()
require("./tests/basic")
local d1 = os.clock() - t1
print(string.format("Basic competency tests finished in %.3fs", d1))
local t2 = os.clock()
require("./tests/bitwise/standard")
require("./tests/bitwise/rshift")
require("./tests/bitwise/arshift")
require("./tests/bitwise/rrotate")
require("./tes... | 192 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/arithmetic/add.luau | luau | .luau | local int64 = require("../../")
local max = int64.from_pair(0xFFFFFFFF, 0xFFFFFFFF)
local zero = int64.from_u32(0)
local one = int64.from_u32(1)
local added_max = int64.add(max, max)
assert(int64.to_hex_string(added_max) == "fffffffffffffffe", "max value + max value was not correct")
assert(added_max.x == 0b111111111... | 891 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/arithmetic/mult.luau | luau | .luau | local int64 = require("../../")
local test_1_a = int64.mult(int64.from_pair(0, 3), int64.from_pair(0, 5))
assert(int64.to_hex_string(test_1_a) == "000000000000000f", "test 1 a (3 * 5) failed")
local test_1_b = int64.mult(int64.from_pair(0, 5), int64.from_pair(0, 3))
assert(int64.to_hex_string(test_1_b) == "00000000000... | 2,115 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/arithmetic/pow.luau | luau | .luau | local int64 = require("../../")
local test_1 = int64.pow(int64.from_pair(0, 3), 4)
assert(int64.to_hex_string(test_1) == "0000000000000051", "pow test 1 (3 ^ 4) failed")
local test_2 = int64.pow(int64.from_pair(0, 5), 1)
assert(int64.to_hex_string(test_2) == "0000000000000005", "pow test 2 (5 ^ 1) failed")
local tes... | 1,190 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/arithmetic/sub.luau | luau | .luau | local int64 = require("../../")
local max = int64.from_pair(0xFFFFFFFF, 0xFFFFFFFF)
local zero = int64.from_u32(0)
local one = int64.from_u32(1)
local subbed_max = int64.sub(max, max)
assert(int64.to_hex_string(subbed_max) == "0000000000000000", "max value - max value was not correct")
assert(subbed_max.x == 0b000000... | 1,143 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/basic.luau | luau | .luau | local int64 = require("../")
local PADDING_STRING = "\a\b\f\n\r\t\v\255\69\127"
-- Constants
assert(int64.ZERO.x == 0, "int64.ZERO x component was wrong")
assert(int64.ZERO.y == 0, "int64.ZERO y component was wrong")
assert(int64.ZERO.z == 0, "int64.ZERO z component was wrong")
assert(int64.ONE.x == 0, "int64.ONE x... | 9,323 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/bitwise/arshift.luau | luau | .luau | local int64 = require("../../")
local arshift_n = int64.from_pair(0x80000000, 0x00000000)
for i = 0, 63 do
local new = int64.arshift(arshift_n, i)
local expected_bin = string.rep("1", i) .. "1" .. string.rep("0", 63 - i)
assert(int64.to_bin_string(new) == expected_bin, `{int64.to_hex_string(arshift_n)} >> {i} was w... | 4,117 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/bitwise/lrotate.luau | luau | .luau | local int64 = require("../../")
local lrotate_n = int64.from_pair(0x80000000, 0x00000000)
assert(int64.lrotate(lrotate_n, 0) == lrotate_n, `{int64.to_hex_string(lrotate_n)} LROT 0 was wrong`)
for i = 1, 63 do
local new = int64.lrotate(lrotate_n, i)
local expected_bin = string.rep("0", 64 - i) .. "1" .. string.rep("... | 4,258 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/bitwise/lshift.luau | luau | .luau | local int64 = require("../../")
local lshift_n = int64.from_pair(0x00000000, 0x00000001)
for i = 0, 63 do
local new = int64.lshift(lshift_n, i)
local expected_bin = string.rep("0", 63 - i) .. "1" .. string.rep("0", i)
assert(int64.to_bin_string(new) == expected_bin, `{int64.to_hex_string(lshift_n)} << {i} was wrong... | 8,211 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/bitwise/rrotate.luau | luau | .luau | local int64 = require("../../")
local rrotate_n = int64.from_pair(0x80000000, 0x00000000)
for i = 0, 63 do
local new = int64.rrotate(rrotate_n, i)
local expected_bin = string.rep("0", i) .. "1" .. string.rep("0", 63 - i)
assert(int64.to_bin_string(new) == expected_bin, `{int64.to_hex_string(rrotate_n)} RROT {i} was... | 4,229 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/bitwise/rshift.luau | luau | .luau | local int64 = require("../../")
local rshift_n = int64.from_pair(0x80000000, 0x00000000)
for i = 0, 63 do
local new = int64.rshift(rshift_n, i)
local expected_bin = string.rep("0", i) .. "1" .. string.rep("0", 63 - i)
assert(int64.to_bin_string(new) == expected_bin, `{int64.to_hex_string(rshift_n)} >>< {i} was wron... | 5,857 |
Dekkonot/int64-luau | Dekkonot-int64-luau-afa518a/tests/bitwise/standard.luau | luau | .luau | local int64 = require("../../")
local band_1 = int64.band(int64.from_pair(0, 0), int64.from_pair(0, 0))
assert(int64.to_hex_string(band_1) == "0000000000000000", "band_1 was wrong")
local band_2 = int64.band(int64.from_pair(0, 1), int64.from_pair(0, 1))
assert(int64.to_hex_string(band_2) == "0000000000000001", "band_... | 3,638 |
dphfox/lingua | dphfox-lingua-575ec37/examples/01-hello-lingua/lune/build-this-example.luau | luau | .luau | --!nocheck
--selene: allow(incorrect_standard_library_use)
local build_single_example = require("../../build-examples/build_single_example")
build_single_example("01-hello-lingua", "bin") | 44 |
dphfox/lingua | dphfox-lingua-575ec37/examples/01-hello-lingua/src-luau/add_panic_handler.luau | luau | .luau | -- When Rust panics, it doesn't exit helpfully by default. This function gives
-- the Rust side an external function it can call with details of the panic,
-- so the error can be emitted on the Luau side instead.
return function(extern_fns)
local current_panic = nil
function extern_fns.panic_reporter(
len_or_byte:... | 160 |
dphfox/lingua | dphfox-lingua-575ec37/examples/02-simple-library/lune/build-this-example.luau | luau | .luau | --!nocheck
--selene: allow(incorrect_standard_library_use)
local build_single_example = require("../../build-examples/build_single_example")
build_single_example("02-simple-library", "lib") | 41 |
dphfox/lingua | dphfox-lingua-575ec37/examples/02-simple-library/src-luau/init.server.luau | luau | .luau | --!nocheck
-- See src/lib.rs for an introduction to this example.
local library = require(script.library)
local prices = {
apple = 10,
orange = 5,
banana = 25
}
local fridge = {
"apple",
"apple",
"banana",
"orange",
"apple",
"orange",
"orange",
"banana",
"banana"
}
local fridge_value = library.calculate_... | 163 |
dphfox/lingua | dphfox-lingua-575ec37/examples/02-simple-library/src-luau/library.luau | luau | .luau | local lingua = require(script.Parent.Parent.lingua)
local library_wasm_loader = require(script.Parent.Parent.target_luau.example_wasm)
local add_panic_handler = require(script.Parent.add_panic_handler)
local wasm_env = { func_list = {} }
add_panic_handler(wasm_env.func_list)
local finish_lingua_init = lingua.init(was... | 202 |
dphfox/lingua | dphfox-lingua-575ec37/examples/build-examples/build_single_example.luau | luau | .luau | -- Lune-style imports make both Luau LSP and Selene very unhappy...
--!nocheck
--!nolint LocalShadow
--selene: allow(incorrect_standard_library_use)
local process = require("@lune/process")
--selene: allow(incorrect_standard_library_use)
local stdio = require("@lune/stdio")
--selene: allow(incorrect_standard_library_us... | 923 |
dphfox/lingua | dphfox-lingua-575ec37/luau/lingua.luau | luau | .luau | --!strict
--Licensed under BSD3 from Lingua, (c) Daniel P H Fox 2024
--------------------------------------------------------------------------------
-- TYPE DEFINITIONS ------------------------------------------------------------
--------------------------------------------------------------------------------
-- Typ... | 2,530 |
OMouta/PyLua | OMouta-PyLua-475c865/.config.luau | luau | .luau | return {
project = {
name = "PyLua",
version = "0.3.0",
description = "Embedded Python Interpreter for Luau",
license = "MIT",
authors = {
"OMouta"
},
},
luau = {
languageMode = "strict",
lint = {
["*"] = true,
... | 241 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/basics.luau | luau | .luau | local PyLua = require("../src/PyLua")
-- Create a Python runtime
local python = PyLua.new()
-- Execute multi-line Python code (statements)
python:execute([[
x = 10
y = 32
print("sum:", x + y)
]])
-- Evaluate a Python expression and get the result in Luau
local value = python:eval("1 + 2 * 3")
print("eval result:", ... | 134 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/builtins.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
print("PyLua Version:", __pylua_version__)
string = "Hello, PyLua!"
print("len of string:", len(string))
print("type of 123:", type(123))
if string[0] == "H":
print("First character is H")
if isinstance(123, int):
print("123 is a... | 120 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/bytes_and_strings.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
s = "hello"
b = b"hello"
print("str:", s)
print("bytes:", b)
print("len(bytes):", len(b))
print("b[1] (first byte):", b[0])
print("concat bytes:", b + b" world")
]])
| 82 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/classes.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
return f"Hello, my name is {self.name} and I am {self.age} years old."
person = Person("Alice", 30)
print(p... | 315 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/collections.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
# Lists, tuples, dicts, sets
nums = [1, 2, 3]
pair = ("a", 42)
conf = {"host": "localhost", "port": 8080}
letters = {"a", "b", "c"}
# Unpacking into new dict
conf2 = {**conf, "debug": True}
print("nums:", nums)
print("pair:", pair)
p... | 252 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/control_flow.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
x = 7
if x < 5:
print("small")
elif x < 10:
print("medium")
else:
print("large")
# chained comparisons combine checks without repeating the middle operand
value = 8
if 5 < value < 10:
print("value is between 5 and 10")... | 442 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/exceptions.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
def divide(a, b):
return a / b
try:
print("divide(10, 2) =", divide(10, 2))
print("divide(5, 0) =", divide(5, 0))
except ZeroDivisionError as e:
print("Error:", e)
try:
array = [1, 2, 3]
print("Accessing array... | 262 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/functions.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
def add(a, b):
return a + b
def greet(name):
return "Hello, " + name
print("add(2, 3) =", add(2, 3))
print(greet("World"))
# Simple function with one default argument
def greet(name, greeting="Hello"):
print(greeting + ",... | 363 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/hello_world.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
python:execute([[
print("Hello world from python!")
]])
| 31 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/imports/lune.luau | luau | .luau | local PyLua = require("../../src/PyLua")
local FileSystem = require("../../src/Packages/FileSystem/Lune")
-- Create a Python runtime
local python = PyLua.new({
fileSystem = FileSystem,
searchPath = {"examples/imports/libs"},
enableFilesystem = true,
})
python:execute([[
import my_lib
my_lib.pretty_print(... | 83 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/imports/lute.luau | luau | .luau | local PyLua = require("../../src/PyLua")
local FileSystem = require("../../src/Packages/FileSystem/Lute")
-- Create a Python runtime
local python = PyLua.new({
fileSystem = FileSystem,
searchPath = {"examples/imports/libs"},
enableFilesystem = true,
})
python:execute([[
import my_lib
my_lib.pretty_print(... | 83 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/imports/virtual.luau | luau | .luau | local PyLua = require("../../src/PyLua")
local FileSystem = require("../../src/Packages/FileSystem/Virtual")
-- 1. Define a native module (Luau table)
local myMathModule = {
add = function(a:number, b:number) return a + b end,
PI = 3.14159
}
-- 2. Define a virtual filesystem (mocking real files)
local files =... | 245 |
OMouta/PyLua | OMouta-PyLua-475c865/examples/interop_minimal.luau | luau | .luau | local PyLua = require("../src/PyLua")
local python = PyLua.new()
-- Minimal interop: expose a Luau value/function via globals
local globals = python:globals()
-- Expose a simple Luau function that multiplies numbers
globals.lua_mul = function(a: number, b: number): number
return a * b
end
python:execute([[
prin... | 119 |
OMouta/PyLua | OMouta-PyLua-475c865/src/Packages/FileSystem/Lute.luau | luau | .luau | --!strict
-- Lute FileSystem Implementation
-- https://lute.luau.org/reference/lute/fs.html
local fs = require("@lute/fs")
local LuteFS = {}
function LuteFS.readFile(path: string): string?
if fs.exists(path) and fs.type(path) == "file" then
return fs.readfiletostring(path)
end
return nil
end
function LuteFS.ex... | 133 |
OMouta/PyLua | OMouta-PyLua-475c865/src/Packages/FileSystem/Virtual.luau | luau | .luau | --!strict
-- Virtual FileSystem (Memory-based)
local VirtualFS = {}
function VirtualFS.new(files: { [string]: string })
return {
readFile = function(path: string): string?
return files[path]
end,
exists = function(path: string): boolean
-- Check exact match
if files[path] then
return true
end
... | 249 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/ast/nodes.luau | luau | .luau | local Nodes = {}
-- Operator types
export type UnaryOpType = "Invert" | "Not" | "UAdd" | "USub"
export type BinOpType =
"Add"
| "Sub"
| "Mult"
| "MatMult"
| "Div"
| "Mod"
| "Pow"
| "LShift"
| "RShift"
| "BitOr"
| "BitXor"
| "BitAnd"
| "FloorDiv"
export type CmpOp = "Eq" | "NotEq" | "Lt" | "LtE" | "Gt" | "... | 2,525 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/ast/visitor.luau | luau | .luau | local Visitor = {}
local nodes = require("./nodes")
type ASTNode = nodes.ASTNode
type AnyNode = nodes.AnyNode
type AnyStmt = nodes.AnyStmt
type AnyExpr = nodes.AnyExpr
-- Base visitor class for AST traversal
export type Visitor = {
visit: (self: Visitor, node: ASTNode) -> any,
generic_visit: (self: Visitor, node: A... | 2,471 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/bytecode/instructions.luau | luau | .luau | local Instructions = {}
local opcodes = require("./opcodes")
type Opcode = opcodes.Opcode
-- Bytecode instruction
export type Instruction = {
opcode: Opcode,
arg: number?, -- Optional numeric argument (index / delta / small int)
lineno: number?, -- Source line for debug / traceback
}
-- Create an instruction; val... | 363 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/compiler/expressions.luau | luau | .luau | local nodes = require("../ast/nodes")
local opcodes = require("../bytecode/opcodes")
local State = require("./state")
type CompilerState = State.CompilerState
type ExprContext = nodes.ExprContext
type ListComp = nodes.ListComp
type BinOpType = nodes.BinOpType
type CmpOp = nodes.CmpOp
local function deepCopy(value: an... | 4,646 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/compiler/init.luau | luau | .luau | local State = require("@self/state")
local expressionsFactory = require("@self/expressions")
local statementsFactory = require("@self/statements")
export type CodeObject = State.CodeObject
local Compiler = {}
local compileStmtImpl: ((State.CompilerState, any) -> ())? = nil
local function compileStmt(st: State.Compi... | 455 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/compiler/state.luau | luau | .luau | local instructions = require("../bytecode/instructions")
local opcodes = require("../bytecode/opcodes")
type Instruction = instructions.Instruction
type Opcode = opcodes.Opcode
export type CodeObject = {
constants: { any },
names: { string },
varnames: { string },
bytecode: { Instruction },
firstlineno: number?,... | 851 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/compiler/statements.luau | luau | .luau | local State = require("./state")
type CompilerState = State.CompilerState
type StatementDeps = {
compileExpr: (CompilerState, any) -> (),
compileAssignmentTarget: (CompilerState, any) -> (),
compileLoadTarget: (CompilerState, any) -> (),
compileStoreTarget: (CompilerState, any) -> (),
resolveBinOpOpcode: (any) -... | 4,190 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/interop/bridge.luau | luau | .luau | local Bridge = {}
local Base = require("../objects/base")
local Collections = require("../objects/collections")
type PyObject = Base.PyObject
type PyType = Base.PyType
type VisitedPy = { [PyObject]: any }
type VisitedLuau = { [any]: PyObject }
type LuauFunctionRecord = { func: (...any) -> any }
type ClassBindingOp... | 3,504 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/objects/builtins.luau | luau | .luau | local Builtins = {}
local base = require("./base")
type PyObject = base.PyObject
-- Forward references to type registration already performed in base bootstrap
-- None
export type PyNone = PyObject & { __type: "NoneType", __value: nil }
function Builtins.None(): PyNone
return base.newNone() :: PyNone
end
-- Boolea... | 3,427 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/objects/collections.luau | luau | .luau | local Collections = {}
local base = require("./base")
local builtins = require("./builtins")
type PyObject = base.PyObject
type PyType = base.PyType
export type PyList = PyObject & { __type: "list", __value: { PyObject } }
export type PyTuple = PyObject & { __type: "tuple", __value: { PyObject } }
export type PyDict ... | 4,982 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/objects/module.luau | luau | .luau | local Base = require("./base")
local Module = {}
-- Register the module type
local moduleType = Base.registerType("module", {
bases = { Base.getTypeObject("object") },
})
function Module.new(name: string, doc: string?): Base.PyObject
local dict = {
["__name__"] = Base.newPyObject("str", name),
["__doc__"] = if... | 185 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/errors.luau | luau | .luau | local errors = {}
export type Location = { line: number, column: number }
local function fmtLocation(loc: Location?): string
if not loc then
return "<unknown>"
end
return string.format("line %d, column %d", loc.line, loc.column)
end
function errors.expected(expected: string, got: string?, loc: Location?)
retur... | 263 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/expressions/binary.luau | luau | .luau | local tokens = require("../../tokens")
local nodes = require("../../ast/nodes")
local precedenceModule = require("../precedence")
export type Token = tokens.Token
export type Expr = nodes.Expr
export type CmpOp = nodes.CmpOp
export type BinaryDeps = {
precedence: typeof(precedenceModule),
parsePrimary: (state: any)... | 1,985 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/expressions/fstring.luau | luau | .luau | local tokens = require("../../tokens")
local nodes = require("../../ast/nodes")
export type Token = tokens.Token
export type Expr = nodes.Expr
export type FStringDeps = {
lexer: any,
wrapCall: (funcName: string, argList: { Expr }, baseNode: Expr, token: Token) -> Expr,
foldConcat: (parts: { Expr }, token: Token) -... | 2,400 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/expressions/init.luau | luau | .luau | -- This module handles expression parsing
local tokens = require("../tokens")
local nodes = require("../ast/nodes")
local precedence = require("./precedence")
local postfix = require("./postfix")
local lexer = require("../lexer")
local utils = require("@self/utils")
local fstringFactory = require("@self/fstring")
l... | 412 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/expressions/lambda.luau | luau | .luau | local tokens = require("../../tokens")
local nodes = require("../../ast/nodes")
export type Token = tokens.Token
export type Expr = nodes.Expr
export type Arguments = nodes.Arguments
local MAX_LAMBDA_NESTING = 64
export type LambdaDeps = {
precedence: any,
postfix: any,
parseBinaryExpression: (state: any, minPrec... | 726 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/expressions/primary.luau | luau | .luau | local tokens = require("../../tokens")
local nodes = require("../../ast/nodes")
local postfix = require("../postfix")
export type Token = tokens.Token
export type Expr = nodes.Expr
export type PrimaryDeps = {
postfix: typeof(postfix),
prefixContains: (prefix: string?, flag: string) -> boolean,
makeStringConstant: ... | 3,035 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/expressions/utils.luau | luau | .luau | local tokens = require("../../tokens")
local nodes = require("../../ast/nodes")
export type Token = tokens.Token
export type Expr = nodes.Expr
export type Arguments = nodes.Arguments
local function prefixContains(prefix: string?, flag: string): boolean
if not prefix then
return false
end
return string.find(prefi... | 854 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/init.luau | luau | .luau | local tokens = require("./tokens")
local nodes = require("./ast/nodes")
local errors = require("@self/errors")
local expressions = require("@self/expressions")
local statements = require("@self/statements")
export type Token = tokens.Token
export type Module = nodes.Module
export type Expr = nodes.Expr
export type Stm... | 691 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/postfix.luau | luau | .luau | local tokens = require("../tokens")
local nodes = require("../ast/nodes")
export type Token = tokens.Token
export type Expr = nodes.Expr
local postfix = {}
-- Forward-declared expression parser injected to avoid cycles
export type ExpressionParser = (state: any) -> Expr
-- Parse function call arguments and keywords... | 774 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/precedence.luau | luau | .luau | local precedence = {}
-- Precedence levels (lower number = lower precedence)
precedence.LEVELS = {
LAMBDA = 0,
OR = 1,
AND = 2,
NOT = 3, -- unary not
IN = 4,
NOT_IN = 4,
IS = 4,
IS_NOT = 4,
LESS = 4,
LESSEQUAL = 4,
GREATER = 4,
GREATEREQUAL = 4,
EQEQUAL = 4,
NOTEQUAL = 4,
VBAR = 5, -- bitwise or
CIRCUM... | 400 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/parser/statements.luau | luau | .luau | local nodes = require("../ast/nodes")
local precedence = require("./precedence")
local expressions = require("./expressions")
export type Expr = nodes.Expr
export type Stmt = nodes.Stmt
local statements = {}
-- Helper to recursively parse assignment targets (including nested tuples)
local function parseForTarget(sta... | 4,648 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/vm/interpreter/blocks.luau | luau | .luau | local FrameModule = require("../frame")
local Stack = require("../stack")
local Base = require("../../objects/base")
local Blocks = {}
export type Frame = FrameModule.Frame
export type Block = FrameModule.Block
local function truncateToBlock(frame: Frame, block: Block)
local target = block.stackSize
local current ... | 865 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/vm/interpreter/call_function.luau | luau | .luau | local FrameModule = require("../frame")
local Functions = require("../../objects/functions")
local Instructions = require("../../bytecode/instructions")
local Base = require("../../objects/base")
local State = require("./state")
local Generator = require("./generator")
local CallFunction = {}
type CallOptions = {
lo... | 1,670 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/vm/interpreter/dispatcher.luau | luau | .luau | local FrameModule = require("../frame")
local Stack = require("../stack")
local Base = require("../../objects/base")
local Collections = require("../../objects/collections")
local ObjBuiltins = require("../../objects/builtins")
local ClassBuilder = require("../../objects/class_builder")
local Exceptions = require("../.... | 6,302 |
OMouta/PyLua | OMouta-PyLua-475c865/src/PyLua/vm/interpreter/generator.luau | luau | .luau | local Base = require("../../objects/base")
local FrameModule = require("../frame")
local State = require("./state")
local Generator = {}
export type PyObject = Base.PyObject
export type VMState = State.VMState
export type ResumeFunction = (
vm: VMState,
frame: FrameModule.Frame,
instruction: any,
constants: { an... | 1,087 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.