Skip to content

Instantly share code, notes, and snippets.

View stravant's full-sized avatar

Mark Langen stravant

  • Beamdog
  • Edmonton AB, Canada
View GitHub Profile
@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
local rowMT = {
__index = function(tb, key)
local col = {}
tb[key] = col
return col
end,
}
local grid = setmetatable({}, {
__index = function(tb, key)
@stravant
stravant / FastSignal.lua
Last active April 29, 2024 23:59
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 = {}
@stravant
stravant / RobloxSignal.lua
Last active April 29, 2024 23:54
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
--------------------------------------------------------------------------------
-- 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
--------------------------------------------------------------------------------
-- Simple Correct Signal Implementation --
-- This is the most straightforwards possible pure Lua implementation of a --
-- Signal class that correctly implements all of the RBXScriptSignal --
-- behavior (Connect, Disconnect, and Wait) --
--------------------------------------------------------------------------------
local Signal = {}
Signal.__index = Signal
local Connection = {}
--------------------------------------------------------------------------------
-- Simple Correct Signal Implementation --
-- This is the most straightforwards possible pure Lua implementation of a --
-- Signal class that correctly implements all of the RBXScriptSignal --
-- behavior (Connect, Disconnect, and Wait) --
--------------------------------------------------------------------------------
local Signal = {}
Signal.__index = Signal
local Connection = {}
@stravant
stravant / GoodSignal.lua
Last active May 14, 2024 22:52
Good Roblox Signal Implementation
--------------------------------------------------------------------------------
-- 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 / convert.py
Created February 28, 2021 04:10
ldraw -> obj converter for Roblox importing
import sys
from pathlib import Path
from math import sqrt
part_name = sys.argv[1]
part_file = part_name + ".dat"
ENTRY_TYPE_COMMENT = '0'
ENTRY_TYPE_SUBMODEL = '1'
ENTRY_TYPE_LINE = '2'
@stravant
stravant / ripper.py
Last active December 1, 2020 13:24
BFBB Decomp Utility Script
import sys
from pathlib import Path
import re
INCLUDE_INSTRUCTION_BYTES = False
def cpp_get_qualified(text):
if text.startswith("Q"):
# multiple qualified name
count = int(text[1])