This commit is contained in:
lx
2026-07-06 14:01:11 -04:00
commit c4f97d729d
16468 changed files with 935321 additions and 0 deletions
@@ -0,0 +1,5 @@
# Generated by Rotriever. Format subject to change in future releases.
name = "roblox/lua-symbol"
version = "0.1.0"
commit = "139fdfe6e4d4eca690887d3beb80e1514af501bf"
source = "git+https://github.rbx.com/roblox/lua-symbol#master"
@@ -0,0 +1,43 @@
--[[
A 'Symbol' is an opaque marker type that can be used to signify unique
statuses. Symbols have the type 'userdata', but when printed to the console,
the name of the symbol is shown.
]]
local Symbol = {}
--[[
Creates a Symbol with the given name.
When printed or coerced to a string, the symbol will turn into the string
given as its name.
]]
function Symbol.named(name)
assert(type(name) == "string", "Symbols must be created using a string name!")
local self = newproxy(true)
local wrappedName = ("Symbol(%s)"):format(name)
getmetatable(self).__tostring = function()
return wrappedName
end
return self
end
--[[
Create an unnamed Symbol. Usually, you should create a named Symbol using
Symbol.named(name)
]]
function Symbol.unnamed()
local self = newproxy(true)
getmetatable(self).__tostring = function()
return "Unnamed Symbol"
end
return self
end
return Symbol
@@ -0,0 +1,45 @@
return function()
local Symbol = require(script.Parent.Symbol)
describe("named", function()
it("should give an opaque object", function()
local symbol = Symbol.named("foo")
expect(symbol).to.be.a("userdata")
end)
it("should coerce to the given name", function()
local symbol = Symbol.named("foo")
expect(tostring(symbol):find("foo")).to.be.ok()
end)
it("should be unique when constructed", function()
local symbolA = Symbol.named("abc")
local symbolB = Symbol.named("abc")
expect(symbolA).never.to.equal(symbolB)
end)
end)
describe("unnamed", function()
it("should give an opaque object", function()
local symbol = Symbol.unnamed()
expect(symbol).to.be.a("userdata")
end)
it("should coerce to some string", function()
local symbol = Symbol.unnamed()
expect(tostring(symbol)).to.be.a("string")
end)
it("should be unique when constructed", function()
local symbolA = Symbol.unnamed()
local symbolB = Symbol.unnamed()
expect(symbolA).never.to.equal(symbolB)
end)
end)
end
@@ -0,0 +1 @@
return require(script.Symbol)