mirror of
https://github.com/CompeyDev/rusty-luau.git
synced 2024-12-12 04:40:40 +00:00
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:
parent
a2a1e9bbf1
commit
f3b77f2575
15 changed files with 57 additions and 231 deletions
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
rule: "convert_require",
|
|
||||||
current: "path",
|
|
||||||
target: {
|
|
||||||
name: "roblox",
|
|
||||||
indexing_style: "property",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
@ -43,7 +43,7 @@ jobs:
|
||||||
run: lune setup
|
run: lune setup
|
||||||
|
|
||||||
- name: Analyze
|
- 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
|
- name: lint
|
||||||
run: selene .
|
run: selene .
|
||||||
|
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -2,7 +2,4 @@
|
||||||
Packages/
|
Packages/
|
||||||
|
|
||||||
# Moonwave compiled docs
|
# Moonwave compiled docs
|
||||||
build/
|
build
|
||||||
|
|
||||||
# Bundled roblox files
|
|
||||||
rbx/
|
|
||||||
|
|
|
@ -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-image]: https://github.com/CompeyDev/rusty-luau/actions/workflows/docs.yaml/badge.svg
|
||||||
[docs-link]: https://rusty-luau.devcomp.xyz/
|
[docs-link]: https://rusty-luau.devcomp.xyz/
|
||||||
[license-image]: https://img.shields.io/github/license/CompeyDev/rusty-luau
|
[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-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
|
[ci-link]: https://github.com/CompeyDev/rusty-luau/actions/workflows/ci.yaml
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"name": "rusty-luau",
|
|
||||||
"tree": {
|
|
||||||
"$path": "rbx",
|
|
||||||
"deps": {
|
|
||||||
"$path": "deps.luau"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
21
deps.luau
21
deps.luau
|
@ -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
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,13 +7,13 @@
|
||||||
would rather import this conversion module.
|
would rather import this conversion module.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local option = require("./option.luau")
|
local option = require("option")
|
||||||
local Option = option.Option
|
local Option = option.Option
|
||||||
export type Option<T> = option.Option<T>
|
export type Option<T> = option.Option<T>
|
||||||
local None = option.None
|
local None = option.None
|
||||||
local Some = option.Some
|
local Some = option.Some
|
||||||
|
|
||||||
local result = require("./result.luau")
|
local result = require("result")
|
||||||
local Result = result.Result
|
local Result = result.Result
|
||||||
export type Result<T, E> = result.Result<T, E>
|
export type Result<T, E> = result.Result<T, E>
|
||||||
local Ok = result.Ok
|
local Ok = result.Ok
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
local isRoblox = _VERSION == "Luau"
|
local task = require("@lune/task")
|
||||||
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 Signal = util.Signal
|
local mod = require("../mod")
|
||||||
type Signal<T...> = util.Signal<T...>
|
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>
|
type Result<T, E> = result.Result<T, E>
|
||||||
local Ok = result.Ok
|
local Ok = result.Ok
|
||||||
local Err = result.Err
|
local Err = result.Err
|
||||||
|
|
||||||
local option = require("./option")
|
local option = require("option")
|
||||||
type Option<T> = option.Option<T>
|
type Option<T> = option.Option<T>
|
||||||
local None = option.None
|
local None = option.None
|
||||||
local Some = option.Some
|
local Some = option.Some
|
||||||
|
@ -91,10 +86,7 @@ local function _constructor<T>(fn: (Signal<()>, Signal<T, Status>) -> ())
|
||||||
_thread = coroutine.create(fn),
|
_thread = coroutine.create(fn),
|
||||||
|
|
||||||
_spawnEvt = Signal.new(),
|
_spawnEvt = Signal.new(),
|
||||||
-- This is a hack to make luau realize that this object and
|
_retEvt = Signal.new(),
|
||||||
-- Future<T> are related
|
|
||||||
_retEvt = Signal.new() :: Signal<T | Result<T, string>, Status>,
|
|
||||||
|
|
||||||
_status = "initialized",
|
_status = "initialized",
|
||||||
} :: Future<T>,
|
} :: Future<T>,
|
||||||
{
|
{
|
||||||
|
@ -204,13 +196,13 @@ end
|
||||||
@param self Future<T>
|
@param self Future<T>
|
||||||
@return T -- The value returned by the function on completion
|
@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
|
while true do
|
||||||
local status: Status, ret: Option<T> = self:poll()
|
local status: Status, ret: Option<T> = self:poll()
|
||||||
|
|
||||||
if status == "ready" then
|
if status == "ready" then
|
||||||
-- Safe to unwrap, we know it must not be nil
|
-- Safe to unwrap, we know it must not be nil
|
||||||
return ret
|
return ret:unwrap()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local tableEq = require("./util.luau").tableEq
|
local tableEq = require("util").tableEq
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
@class Option
|
@class Option
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local tableEq = require("./util.luau").tableEq
|
local tableEq = require("util").tableEq
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
@class Result
|
@class Result
|
||||||
|
|
119
lib/util.luau
119
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: <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
|
-- From https://gist.github.com/sapphyrus/fd9aeb871e3ce966cc4b0b969f62f539
|
||||||
local function tableEq(tbl1, tbl2)
|
local function tableEq(tbl1, tbl2)
|
||||||
-- if tbl1 == tbl2 then
|
if tbl1 == tbl2 then
|
||||||
-- return true
|
return true
|
||||||
-- elseif type(tbl1) == "table" and type(tbl2) == "table" then
|
elseif type(tbl1) == "table" and type(tbl2) == "table" then
|
||||||
-- for key1, value1 in pairs(tbl1) do
|
for key1, value1 in pairs(tbl1) do
|
||||||
-- local value2 = tbl2[key1]
|
local value2 = tbl2[key1]
|
||||||
|
|
||||||
-- if value2 == nil then
|
if value2 == nil then
|
||||||
-- -- avoid the type call for missing keys in tbl2 by directly comparing with nil
|
-- avoid the type call for missing keys in tbl2 by directly comparing with nil
|
||||||
-- return false
|
return false
|
||||||
-- elseif value1 ~= value2 then
|
elseif value1 ~= value2 then
|
||||||
-- if type(value1) == "table" and type(value2) == "table" then
|
if type(value1) == "table" and type(value2) == "table" then
|
||||||
-- if not tableEq(value1, value2) then
|
if not tableEq(value1, value2) then
|
||||||
-- return false
|
return false
|
||||||
-- end
|
end
|
||||||
-- else
|
else
|
||||||
-- return false
|
return false
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
|
|
||||||
-- -- check for missing keys in tbl1
|
-- check for missing keys in tbl1
|
||||||
-- for key2, _ in pairs(tbl2) do
|
for key2, _ in pairs(tbl2) do
|
||||||
-- if tbl1[key2] == nil then
|
if tbl1[key2] == nil then
|
||||||
-- return false
|
return false
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
|
|
||||||
-- return true
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- return false
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local RobloxEvent = {}
|
return false
|
||||||
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,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tableEq = tableEq,
|
tableEq = tableEq,
|
||||||
Signal = setmetatable({}, {
|
|
||||||
__index = if isLune then LuauSignal elseif isRoblox then RobloxEvent else error("Unsupported runtime!"),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
14
mod.luau
Normal file
14
mod.luau
Normal 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,
|
||||||
|
}
|
|
@ -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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Reference in a new issue