Skip to content

Instantly share code, notes, and snippets.

View stravant's full-sized avatar

Mark Langen stravant

  • Roblox
  • Bay Area
View GitHub Profile
@stravant
stravant / RobloxSignal.lua
Last active January 27, 2025 13:42
An implementation of RBXScriptSignal based on a wrapper around a BindableEvent
--------------------------------------------------------------------------------
-- Argument By-Reference Signal Wrapper --
-- This is a signal class implemented by wrapping a BindableEvent, which --
-- passes the event arguments by reference instead of by value, and which --
-- still works corectly even with SignalBehavior = deferred. --
--------------------------------------------------------------------------------
local Signal = {}
Signal.__index = Signal
@stravant
stravant / FastSignal.lua
Last active December 15, 2024 18:38
An implementation of RBXScriptSignal which sacrifices correctness to be as performant as possible
--------------------------------------------------------------------------------
-- Fast Signal-like class --
-- This is a Signal class that is implemented in the most performant way --
-- possible, sacrificing correctness. The event handlers will be called --
-- directly, so it is not safe to yield in them, and it is also not safe to --
-- connect new handlers in the middle of a handler (though it is still safe --
-- for a handler to specifically disconnect itself) --
--------------------------------------------------------------------------------
local Signal = {}
local rowMT = {
__index = function(tb, key)
local col = {}
tb[key] = col
return col
end,
}
local grid = setmetatable({}, {
__index = function(tb, key)
@stravant
stravant / Upvalue.bench.lua
Created August 15, 2021 20:23
Showing the cost of not caching the upvalue
local upValueArray = {1}
return {
ParameterGenerator = function()
end;
Functions = {
["Empty loop"] = function()
for i = 1, 10000 do
@stravant
stravant / DictVsArrayVector.bench.lua
Created August 15, 2021 20:32
Comparison of dict vs array vector performance in Roblox Lua
local ArrayVector1 = {1, 2, 3, 4}
local ArrayVector2 = {1, 2, 3, 4}
local ArrayVector3 = {1, 2, 3, 4}
local ArrayVector4 = {1, 2, 3, 4}
local DictVector1 = {x = 1, y = 2, z = 3, w = 4}
local DictVector2 = {x = 1, y = 2, z = 3, w = 4}
local DictVector3 = {x = 1, y = 2, z = 3, w = 4}
local DictVector4 = {x = 1, y = 2, z = 3, w = 4}
@stravant
stravant / ArrayGoodSignal.lua
Created August 15, 2021 20:52
Array based GoodSignal (not as good as the field based one)
--------------------------------------------------------------------------------
-- Batched Yield-Safe Signal Implementation --
-- This is a Signal class which has effectively identical behavior to a --
-- normal RBXScriptSignal, with the only difference being a couple extra --
-- stack frames at the bottom of the stack trace when an error is thrown. --
-- This implementation caches runner coroutines, so the ability to yield in --
-- the signal handlers comes at minimal extra cost over a naive signal --
-- implementation that either always or never spawns a thread. --
-- --
-- API: --
@stravant
stravant / SignalTypes.bench
Created August 15, 2021 20:55
Benchmark for different types of signal
local ASignal = require(game:GetService("ServerStorage").ASignal)
local FSignal = require(game:GetService("ServerStorage").FSignal)
local function FireMany(sig)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
@stravant
stravant / fetch_masterduel_info.py
Created February 14, 2022 05:32
Fetch info from masterduelmeta.com to compute relative value of SRs / URs.
import requests
import json
import urllib.parse
import re
top_decks_url = "https://www.masterduelmeta.com/api/v1/top-decks?limit=0"
included_cards = {
"Lightning Storm": 1,
"Solemn Judgment": 1,
@stravant
stravant / createSharedToolbar.lua
Created June 23, 2022 07:02
Module that manages a toolbar shared by multiple plugins in a way that supports reloading.
local CoreGui = game:GetService("CoreGui")
export type SharedToolbarSettings = {
ButtonName: string,
ButtonIcon: string,
ButtonTooltip: string,
ToolbarName: string,
CombinerName: string,
ClickedFn: () -> (),
@stravant
stravant / createSharedToolbar.lua
Created August 15, 2022 07:48
createSharedToolbar Module
local CoreGui = game:GetService("CoreGui")
export type SharedToolbarSettings = {
ButtonName: string,
ButtonIcon: string,
ButtonTooltip: string,
ToolbarName: string,
CombinerName: string,
ClickedFn: () -> (),