From f3b77f25755fb010821e04b7712d5c8f5c73ea7d Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Tue, 11 Jun 2024 19:49:22 +0530 Subject: [PATCH] revert: roblox support from main Undoing experimental Roblox bundling support simply because I cannot maintain it. See branch roblox-support for the reverted version. --- .darklua.json5 | 12 ---- .github/workflows/ci.yaml | 2 +- .gitignore | 5 +- README.md | 2 +- default.project.json | 9 --- deps.luau | 21 ------- dev.project.json | 17 ------ lib/conversion.luau | 4 +- lib/future.luau | 26 +++----- lib/option.luau | 2 +- lib/result.luau | 2 +- lib/util.luau | 121 +++++++++----------------------------- mod.luau | 14 +++++ rusty-luau.luau | 0 sourcemap.json | 51 ---------------- 15 files changed, 57 insertions(+), 231 deletions(-) delete mode 100644 .darklua.json5 delete mode 100644 default.project.json delete mode 100644 deps.luau delete mode 100644 dev.project.json create mode 100644 mod.luau delete mode 100644 rusty-luau.luau delete mode 100644 sourcemap.json diff --git a/.darklua.json5 b/.darklua.json5 deleted file mode 100644 index a4f1af5..0000000 --- a/.darklua.json5 +++ /dev/null @@ -1,12 +0,0 @@ -{ - rules: [ - { - rule: "convert_require", - current: "path", - target: { - name: "roblox", - indexing_style: "property", - }, - }, - ], -} \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f7116a..13c4557 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 . diff --git a/.gitignore b/.gitignore index 7f98f06..6bf7103 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,4 @@ Packages/ # Moonwave compiled docs -build/ - -# Bundled roblox files -rbx/ \ No newline at end of file +build diff --git a/README.md b/README.md index 874c2d3..8c80dd6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/default.project.json b/default.project.json deleted file mode 100644 index 5871c4f..0000000 --- a/default.project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "rusty-luau", - "tree": { - "$path": "rbx", - "deps": { - "$path": "deps.luau" - } - } -} \ No newline at end of file diff --git a/deps.luau b/deps.luau deleted file mode 100644 index 698eeff..0000000 --- a/deps.luau +++ /dev/null @@ -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 diff --git a/dev.project.json b/dev.project.json deleted file mode 100644 index 05ed0ab..0000000 --- a/dev.project.json +++ /dev/null @@ -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 - } - } - } - } -} \ No newline at end of file diff --git a/lib/conversion.luau b/lib/conversion.luau index e8c0dde..a55588b 100644 --- a/lib/conversion.luau +++ b/lib/conversion.luau @@ -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 = option.Option local None = option.None local Some = option.Some -local result = require("./result.luau") +local result = require("result") local Result = result.Result export type Result = result.Result local Ok = result.Ok diff --git a/lib/future.luau b/lib/future.luau index 6fff49d..b6d836b 100644 --- a/lib/future.luau +++ b/lib/future.luau @@ -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 = util.Signal +local mod = require("../mod") +local Signal = mod.signal +type Signal = mod.Signal -local task = requires.task - -local result = require("./result") +local result = require("result") type Result = result.Result local Ok = result.Ok local Err = result.Err -local option = require("./option") +local option = require("option") type Option = option.Option local None = option.None local Some = option.Some @@ -91,10 +86,7 @@ local function _constructor(fn: (Signal<()>, Signal) -> ()) _thread = coroutine.create(fn), _spawnEvt = Signal.new(), - -- This is a hack to make luau realize that this object and - -- Future are related - _retEvt = Signal.new() :: Signal, Status>, - + _retEvt = Signal.new(), _status = "initialized", } :: Future, { @@ -204,13 +196,13 @@ end @param self Future @return T -- The value returned by the function on completion ]=] -function Future.await(self: Future): Option +function Future.await(self: Future): T while true do local status: Status, ret: Option = self:poll() if status == "ready" then -- Safe to unwrap, we know it must not be nil - return ret + return ret:unwrap() end end end diff --git a/lib/option.luau b/lib/option.luau index 764f0ed..4a20824 100644 --- a/lib/option.luau +++ b/lib/option.luau @@ -1,4 +1,4 @@ -local tableEq = require("./util.luau").tableEq +local tableEq = require("util").tableEq --[=[ @class Option diff --git a/lib/result.luau b/lib/result.luau index c8837c5..deca2dc 100644 --- a/lib/result.luau +++ b/lib/result.luau @@ -1,4 +1,4 @@ -local tableEq = require("./util.luau").tableEq +local tableEq = require("util").tableEq --[=[ @class Result diff --git a/lib/util.luau b/lib/util.luau index 306917a..743e413 100644 --- a/lib/util.luau +++ b/lib/util.luau @@ -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: () -> Signal, -} = requires.signal - -export type Signal = { - Fire: (self: Signal, T...) -> (), - Connect: (self: Signal, callback: (T...) -> ()) -> () -> (), - Once: (self: Signal, callback: (T...) -> ()) -> () -> (), - DisconnectAll: (self: Signal) -> (), -} - -- 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 = Signal & { - _inner: BindableEvent, -} - -function RobloxEvent.new() - local instance = Instance.new("BindableEvent") - instance.Parent = script - instance.Name = tostring({}):split(" ")[2] - - return setmetatable({ - _inner = instance, - }, { - __index = RobloxEvent, - }) -end - -function RobloxEvent.Fire(self: RobloxEvent, ...: T...) - return self._inner:Fire(...) -end - -function RobloxEvent.Connect(self: RobloxEvent, callback: (T...) -> ()) - local conn = self._inner.Event:Connect(callback) - - return { - DisconnectAll = function(self: RobloxEvent) - conn:Disconnect() - self._inner:Destroy() - end, - } -end - -function RobloxEvent.Once(self: RobloxEvent, callback: (T...) -> ()) - local conn = self._inner.Event:Connect(callback) - - return { - DisconnectAll = function(self: RobloxEvent) - 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!"), - }), } diff --git a/mod.luau b/mod.luau new file mode 100644 index 0000000..f5b03c6 --- /dev/null +++ b/mod.luau @@ -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 = _signal.luauSignal +local signal: { + new: () -> Signal, +} = + luau.load('local task = require("@lune/task")\n' .. fs.readFile(SIGNAL_PATH))() + +return { + signal = signal, +} diff --git a/rusty-luau.luau b/rusty-luau.luau deleted file mode 100644 index e69de29..0000000 diff --git a/sourcemap.json b/sourcemap.json deleted file mode 100644 index 7ce5792..0000000 --- a/sourcemap.json +++ /dev/null @@ -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" - ] - } - ] -}