Skip to content

Commit 9f52028

Browse files
committed
Initial commit
0 parents  commit 9f52028

File tree

11 files changed

+237
-0
lines changed

11 files changed

+237
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 4
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = false
9+
10+
[*.lua]
11+
indent_style = tab
12+
13+
[*.json]
14+
indent_style = space

.github/workflows/publish-docs.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: main
2+
on:
3+
push:
4+
branches: ["main"]
5+
jobs:
6+
status:
7+
runs-on: ubuntu-latest
8+
name: Publish docs to GitHub Pages
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: "22"
14+
- run: npm i -g moonwave@latest
15+
- name: Publish
16+
run: |
17+
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
18+
git config --global user.email "support+actions@github.com"
19+
git config --global user.name "github-actions-bot"
20+
moonwave build --publish
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Project model file
2+
/out
3+
4+
# Roblox Studio lock files
5+
/*.rbxlx.lock
6+
/*.rbxl.lock
7+
8+
# Sourcemaps
9+
sourcemap.json

LICENSE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 Blerru
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BindableEventWrapper
2+
3+
A BindableEventWrapper is an object that wraps a [BindableEvent](https://create.roblox.com/docs/reference/engine/classes/BindableEvent) and provides an API similar to that of normal signal libraries.
4+
5+
## Usage
6+
7+
To use this, simply create a new instance by calling new. Afterwards, use the created instance like an [RBXScriptSignal](https://create.roblox.com/docs/reference/engine/datatypes/RBXScriptSignal). Unlike an RBXScriptSignal, there is a [Fire](https://blru.github.io/roblox-bindable-event-wrapper/api/BindableEventWrapper#Fire) method to fire the event.
8+
9+
```lua
10+
local BindableEventWrapper = require(Path.To.Module)
11+
12+
local foodConsumed = BindableEventWrapper.new()
13+
14+
foodConsumed:Connect(function(consumer: Player, kind: string)
15+
print(consumer.Name .. " ate a " .. kind .. ".")
16+
end)
17+
18+
foodConsumed:Fire(someone, "carrot")
19+
```
20+
21+
For more information, refer to the [documentation](http://blru.github.io/roblox-bindable-event-wrapper/api/BindableEventWrapper).
22+
23+
## Why use this?
24+
25+
Uh..
26+
27+
> "Your scientists were so preoccupied with whether or not they could, they didn't stop to think if they should."
28+
29+
Realistically, it is oftentimes better to use an actual signal implementation, such as [FastSignal](https://github.com/RBLXUtils/FastSignal), especially if you want to get around the [limitations](https://create.roblox.com/docs/scripting/events/bindable#argument-limitations) imposed by traditional BindableEvents.
30+

aftman.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
2+
# For more information, see https://github.com/LPGhatguy/aftman
3+
4+
# To add a new tool, add an entry to this table.
5+
[tools]
6+
rojo = "rojo-rbx/rojo@7.5.1"
7+
# rojo = "rojo-rbx/rojo@6.2.0"

default.project.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "BindableEventWrapper",
3+
"tree": {
4+
"$path": "src"
5+
}
6+
}

moonwave.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title = "BindableEventWrapper"
2+
gitRepoUrl = "https://github.com/blru/roblox-bindable-event-wrapper"
3+
gitSourceBranch = "main"
4+
changelog = false
5+
6+
[home]
7+
enabled = false
8+
includeReadme = false
9+
10+
[docusaurus]
11+
tagline = "A wrapper around a BindableEvent"

scripts/build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
mkdir -p ./out
4+
rojo build --output ./out/bindable-event-wrapper.rbxm default.project.json

src/init.luau

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
--[=[
2+
@class BindableEventWrapper
3+
4+
A wrapper around a [BindableEvent] that exposes a similar API to that of a normal signal library.
5+
6+
Please note that this has the same [limitations](https://create.roblox.com/docs/scripting/events/bindable#argument-limitations) as a regular BindableEvent.
7+
8+
```lua
9+
local roundEnded = BindableEventWrapper.new()
10+
11+
foodEaten:Connect(function(winner)
12+
print(winner .. " won the round!")
13+
end)
14+
15+
foodEaten:Fire("Jerry")
16+
```
17+
]=]
18+
local BindableEventWrapper = {}
19+
BindableEventWrapper.__index = BindableEventWrapper
20+
21+
type BindableEventWrapper = typeof(setmetatable({} :: {}, BindableEventWrapper))
22+
23+
--[=[
24+
@prop _internal BindableEvent
25+
@private
26+
@within BindableEventWrapper
27+
28+
The underlying bindable event used by the class
29+
]=]
30+
31+
--[=[
32+
@within BindableEventWrapper
33+
@param event BindableEvent? -- If this is not nil, the wrapper will wrap the provided [BindableEvent] instead of creating a new one.
34+
35+
Instantiates a new BindableEventWrapper.
36+
]=]
37+
function BindableEventWrapper.new(event: BindableEvent?)
38+
assert(
39+
event == nil
40+
or (typeof(event) == "Instance" and event:IsA("BindableEvent")),
41+
"event must be nil or an instance of BindableEvent"
42+
)
43+
44+
if event == nil then
45+
event = Instance.new("BindableEvent")
46+
end
47+
48+
local self = {
49+
_inner = event,
50+
}
51+
52+
setmetatable(self, BindableEventWrapper)
53+
54+
return self
55+
end
56+
57+
--[=[
58+
@within BindableEventWrapper
59+
60+
Fires the internal [BindableEvent].
61+
62+
See [BindableEvent:Fire]
63+
]=]
64+
function BindableEventWrapper.Fire(self: BindableEventWrapper, ...: any)
65+
self._inner:Fire(...)
66+
end
67+
68+
--[=[
69+
@within BindableEventWrapper
70+
71+
Connects to the internal [BindableEvent's Event](https://create.roblox.com/docs/reference/engine/classes/BindableEvent#Event) and returns the [RBXScriptConnection](https://create.roblox.com/docs/reference/engine/datatypes/RBXScriptConnection) representing it.
72+
73+
See [RBXScriptSignal:Connect]
74+
]=]
75+
function BindableEventWrapper.Connect(
76+
self: BindableEventWrapper,
77+
callback: (...any) -> ()
78+
): RBXScriptConnection
79+
return self._inner.Event:Connect(callback)
80+
end
81+
82+
--[=[
83+
@within BindableEventWrapper
84+
85+
See [RBXScriptSignal:ConnectParallel]
86+
]=]
87+
function BindableEventWrapper.ConnectParallel(
88+
self: BindableEventWrapper,
89+
callback: (...any) -> ()
90+
): RBXScriptConnection
91+
return self._inner.Event:ConnectParallel(callback)
92+
end
93+
94+
--[=[
95+
@within BindableEventWrapper
96+
97+
Connects to the [internal BindableEvent's Event](https://create.roblox.com/docs/reference/engine/classes/BindableEvent#Event) such that the connection is disconnected after the first event is delivered. Returns the [RBXScriptConnection](https://create.roblox.com/docs/reference/engine/datatypes/RBXScriptConnection) representing the connection.
98+
99+
See [RBXScriptSignal:Once]
100+
]=]
101+
function BindableEventWrapper.Once(
102+
self: BindableEventWrapper,
103+
callback: (...any) -> ()
104+
): RBXScriptConnection
105+
return self._inner.Event:Once(callback)
106+
end
107+
108+
--[=[
109+
@within BindableEventWrapper
110+
@yields
111+
112+
Yields until the internal [BindableEvent's Event](https://create.roblox.com/docs/reference/engine/classes/BindableEvent#Event) fires. Returns the arguments provided by the signal.
113+
114+
See [RBXScriptSignal:Wait]
115+
]=]
116+
function BindableEventWrapper.Wait(self: BindableEventWrapper): ...any
117+
return self._inner.Event:Wait()
118+
end
119+
120+
return BindableEventWrapper

0 commit comments

Comments
 (0)