revert: roblox support from main

Undoing experimental Roblox bundling support simply because I cannot maintain it. See branch roblox-support for the reverted version.
This commit is contained in:
Erica Marigold 2024-06-11 19:49:22 +05:30
parent a2a1e9bbf1
commit f3b77f2575
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
15 changed files with 57 additions and 231 deletions

View file

@ -1,12 +0,0 @@
{
rules: [
{
rule: "convert_require",
current: "path",
target: {
name: "roblox",
indexing_style: "property",
},
},
],
}

View file

@ -43,7 +43,7 @@ jobs:
run: lune setup
- name: Analyze
run: luau-lsp analyze --ignore="Packages/**" --settings=".vscode/settings.json" lib/ examples/ deps.luau
run: luau-lsp analyze --ignore="Packages/**" --settings=".vscode/settings.json" lib/ examples/ mod.luau
- name: lint
run: selene .

5
.gitignore vendored
View file

@ -2,7 +2,4 @@
Packages/
# Moonwave compiled docs
build/
# Bundled roblox files
rbx/
build

View file

@ -21,6 +21,6 @@ currently, the following implementations are available:
[docs-image]: https://github.com/CompeyDev/rusty-luau/actions/workflows/docs.yaml/badge.svg
[docs-link]: https://rusty-luau.devcomp.xyz/
[license-image]: https://img.shields.io/github/license/CompeyDev/rusty-luau
[license-link]: https://github.com/CompeyDev/rusty-luau/blob/main/LICENSE.md
[license-link]: /LICENSE.md
[ci-image]: https://github.com/CompeyDev/rusty-luau/actions/workflows/ci.yaml/badge.svg
[ci-link]: https://github.com/CompeyDev/rusty-luau/actions/workflows/ci.yaml

View file

@ -1,9 +0,0 @@
{
"name": "rusty-luau",
"tree": {
"$path": "rbx",
"deps": {
"$path": "deps.luau"
}
}
}

View file

@ -1,21 +0,0 @@
-- All types from https://github.com/ffrostflame/LuauSignal/blob/f8305cc6b/src/init.luau#L97-L110
return function(isRoblox: boolean, isLune: boolean)
local SIGNAL_PATH = "Packages/_Index/ffrostflame_luausignal@0.2.4/luausignal/src/init.luau"
local signal = if isRoblox
then require(script.Parent.Parent.luausignal :: ModuleScript)
elseif isLune then require("@lune/luau").load(
'local task = require("@lune/task")\n' .. require("@lune/fs").readFile(SIGNAL_PATH)
)()
else error("Unsupported runtime: " .. _VERSION)
local task = if isRoblox
then task
elseif isLune then require("@lune/task")
else error("Unsupported runtime: " .. _VERSION)
return {
signal = signal,
task = task,
}
end

View file

@ -1,17 +0,0 @@
{
"name": "rusty-luau",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"Packages": {
"$path": "Packages",
"$ignoreUnknownInstances": true,
"rusty-luau": {
"$path": "default.project.json",
"$ignoreUnknownInstances": true
}
}
}
}
}

View file

@ -7,13 +7,13 @@
would rather import this conversion module.
]]
local option = require("./option.luau")
local option = require("option")
local Option = option.Option
export type Option<T> = option.Option<T>
local None = option.None
local Some = option.Some
local result = require("./result.luau")
local result = require("result")
local Result = result.Result
export type Result<T, E> = result.Result<T, E>
local Ok = result.Ok

View file

@ -1,20 +1,15 @@
local isRoblox = _VERSION == "Luau"
local isLune = _VERSION:find("Lune") == 1
local deps = if isLune then require("../deps") else require(script.Parent.deps)
local requires = deps(isRoblox, isLune)
local util = require("./util.luau")
local task = require("@lune/task")
local Signal = util.Signal
type Signal<T...> = util.Signal<T...>
local mod = require("../mod")
local Signal = mod.signal
type Signal<T...> = mod.Signal<T...>
local task = requires.task
local result = require("./result")
local result = require("result")
type Result<T, E> = result.Result<T, E>
local Ok = result.Ok
local Err = result.Err
local option = require("./option")
local option = require("option")
type Option<T> = option.Option<T>
local None = option.None
local Some = option.Some
@ -91,10 +86,7 @@ local function _constructor<T>(fn: (Signal<()>, Signal<T, Status>) -> ())
_thread = coroutine.create(fn),
_spawnEvt = Signal.new(),
-- This is a hack to make luau realize that this object and
-- Future<T> are related
_retEvt = Signal.new() :: Signal<T | Result<T, string>, Status>,
_retEvt = Signal.new(),
_status = "initialized",
} :: Future<T>,
{
@ -204,13 +196,13 @@ end
@param self Future<T>
@return T -- The value returned by the function on completion
]=]
function Future.await<T>(self: Future<T>): Option<T>
function Future.await<T>(self: Future<T>): T
while true do
local status: Status, ret: Option<T> = self:poll()
if status == "ready" then
-- Safe to unwrap, we know it must not be nil
return ret
return ret:unwrap()
end
end
end

View file

@ -1,4 +1,4 @@
local tableEq = require("./util.luau").tableEq
local tableEq = require("util").tableEq
--[=[
@class Option

View file

@ -1,4 +1,4 @@
local tableEq = require("./util.luau").tableEq
local tableEq = require("util").tableEq
--[=[
@class Result

View file

@ -1,105 +1,38 @@
local isRoblox = _VERSION == "Luau"
local isLune = _VERSION:find("Lune") == 1
local deps = if isLune
then require("../deps")
elseif isRoblox then require(script.Parent.deps)
else error("Unsupported Runtime!")
local requires = deps(isRoblox, isLune)
local LuauSignal: {
new: <T...>() -> Signal<T...>,
} = requires.signal
export type Signal<T...> = {
Fire: (self: Signal<T...>, T...) -> (),
Connect: (self: Signal<T...>, callback: (T...) -> ()) -> () -> (),
Once: (self: Signal<T...>, callback: (T...) -> ()) -> () -> (),
DisconnectAll: (self: Signal<T...>) -> (),
}
-- From https://gist.github.com/sapphyrus/fd9aeb871e3ce966cc4b0b969f62f539
local function tableEq(tbl1, tbl2)
-- if tbl1 == tbl2 then
-- return true
-- elseif type(tbl1) == "table" and type(tbl2) == "table" then
-- for key1, value1 in pairs(tbl1) do
-- local value2 = tbl2[key1]
if tbl1 == tbl2 then
return true
elseif type(tbl1) == "table" and type(tbl2) == "table" then
for key1, value1 in pairs(tbl1) do
local value2 = tbl2[key1]
-- if value2 == nil then
-- -- avoid the type call for missing keys in tbl2 by directly comparing with nil
-- return false
-- elseif value1 ~= value2 then
-- if type(value1) == "table" and type(value2) == "table" then
-- if not tableEq(value1, value2) then
-- return false
-- end
-- else
-- return false
-- end
-- end
-- end
if value2 == nil then
-- avoid the type call for missing keys in tbl2 by directly comparing with nil
return false
elseif value1 ~= value2 then
if type(value1) == "table" and type(value2) == "table" then
if not tableEq(value1, value2) then
return false
end
else
return false
end
end
end
-- -- check for missing keys in tbl1
-- for key2, _ in pairs(tbl2) do
-- if tbl1[key2] == nil then
-- return false
-- end
-- end
-- check for missing keys in tbl1
for key2, _ in pairs(tbl2) do
if tbl1[key2] == nil then
return false
end
end
-- return true
-- end
return true
end
-- return false
return true
end
local RobloxEvent = {}
type RobloxEvent<T...> = Signal<T...> & {
_inner: BindableEvent,
}
function RobloxEvent.new<T...>()
local instance = Instance.new("BindableEvent")
instance.Parent = script
instance.Name = tostring({}):split(" ")[2]
return setmetatable({
_inner = instance,
}, {
__index = RobloxEvent,
})
end
function RobloxEvent.Fire<T...>(self: RobloxEvent<T...>, ...: T...)
return self._inner:Fire(...)
end
function RobloxEvent.Connect<T...>(self: RobloxEvent<T...>, callback: (T...) -> ())
local conn = self._inner.Event:Connect(callback)
return {
DisconnectAll = function<T...>(self: RobloxEvent<T...>)
conn:Disconnect()
self._inner:Destroy()
end,
}
end
function RobloxEvent.Once<T...>(self: RobloxEvent<T...>, callback: (T...) -> ())
local conn = self._inner.Event:Connect(callback)
return {
DisconnectAll = function<T...>(self: RobloxEvent<T...>)
conn:Disconnect()
self._inner:Destroy()
end,
}
return false
end
return {
tableEq = tableEq,
Signal = setmetatable({}, {
__index = if isLune then LuauSignal elseif isRoblox then RobloxEvent else error("Unsupported runtime!"),
}),
}

14
mod.luau Normal file
View file

@ -0,0 +1,14 @@
local luau = require("@lune/luau")
local fs = require("@lune/fs")
local SIGNAL_PATH = "Packages/_Index/ffrostflame_luausignal@0.2.4/luausignal/src/init.luau"
local _signal = require(SIGNAL_PATH)
export type Signal<T...> = _signal.luauSignal<T...>
local signal: {
new: <T...>() -> Signal<T...>,
} =
luau.load('local task = require("@lune/task")\n' .. fs.readFile(SIGNAL_PATH))()
return {
signal = signal,
}

View file

View file

@ -1,51 +0,0 @@
{
"name": "rusty-luau",
"className": "Folder",
"filePaths": [
"default.project.json"
],
"children": [
{
"name": "conversion",
"className": "ModuleScript",
"filePaths": [
"rbx/conversion.luau"
]
},
{
"name": "future",
"className": "ModuleScript",
"filePaths": [
"rbx/future.luau"
]
},
{
"name": "option",
"className": "ModuleScript",
"filePaths": [
"rbx/option.luau"
]
},
{
"name": "result",
"className": "ModuleScript",
"filePaths": [
"rbx/result.luau"
]
},
{
"name": "util",
"className": "ModuleScript",
"filePaths": [
"rbx/util.luau"
]
},
{
"name": "deps",
"className": "ModuleScript",
"filePaths": [
"deps.luau"
]
}
]
}