Skip to content

Instantly share code, notes, and snippets.

View thevurv's full-sized avatar
🛠️
Working on mekkanics

Vurv thevurv

🛠️
Working on mekkanics
View GitHub Profile
@thevurv
thevurv / luajs.lua
Last active April 9, 2025 03:33
JS-style syntax for Lua.
---@class Class
---@overload fun(t: table): Class
---@field constructor function
---@field name string
---@field prototype table<string, any>
---@class StaticField
---@field name string
---@type table<string, Class>
@thevurv
thevurv / tjson.lua
Created July 2, 2023 03:42
Tiny JSON parser in Lua.
-- JSON parser originally from qjson.lua
local function decode(json --[[@param json string]]) ---@return table
local ptr = 0
local function consume(pattern --[[@param pattern string]]) ---@return string?
local start = json:find("^%S", ptr)
if start then ptr = start end
local start, finish, match = json:find(pattern, ptr)
if start then
ptr = finish + 1
const rgx = /virtual\s+(\w+)\s*\*?\s+\*?(\w+)\(([^)]+)\)/g;
const foo = document.getElementById("area");
const textarea = document.getElementById("code");
const btn = document.getElementById("btn");
btn.onclick = function() {
const code = textarea.value;
let submissions = code.matchAll(rgx);
const outputs = [];
let ind = 0;
args=args or{...}local a;local setmetatable=setmetatable;local assert=assert;local error=error;local bit=bit;local math=math;local b=bit.tobit;local c=bit.arshift;local d=bit.rshift;local e=bit.lshift;local f=bit.band;local g=bit.bor;local h=bit.bxor;local i=bit.ror;local j=bit.rol;local k=math.huge;local l=math.floor;local m=math.ceil;local n=math.abs;local o=math.max;local p=math.min;local q=math.pow;local r=math.sqrt;local s=math.ldexp;local t=math.frexp;local u=math.log;if jit and jit.version_num<20100 then function t(v)local w=n(v)if v~=0 and w~=k then local x=o(-1023,l(u(w,2)+1))local y=w*q(2,-x)if v<0 then y=-y end;return y,x end;return v,0 end end;local function z(A)if A>=0 then return l(A)end;return m(A)end;local function B(C,D)return (setmetatable({C,D},a))end;local function E(A)local D=b(l(A/2^32))local C=b(A%2^32)return (setmetatable({C,D},a))end;_G.__LONG_INT__=B;_G.__LONG_INT_N__=E;local F={}local G={}local H=setmetatable({},{__mode="k"})local I={}local J={}local K={}local L={arrays={},ptrArrays
@thevurv
thevurv / streamcore_compat.e2
Created September 25, 2021 15:53
WebAudio compatibility with streamcore creations using user defined functions.
@name Streamcore Replacement with WebAudio Backend
@persist WSTRCORE_TBL:table
function streamHelp() {}
function number streamCanStart() { return webAudioCanCreate() }
function entity:streamStart(Index, Url:string) {
local Wa = webAudio(Url)
Wa:setParent(This)
Wa:play()
@thevurv
thevurv / burst_limit.lua
Created August 27, 2021 02:16
Burst limit in lua
-- Burst Limit for Garrysmod/Wiremod
local Burst = setmetatable({}, {
__call = function(self, max, regen_time)
return setmetatable({
max = max, -- Will start full.
regen = regen_time,
tracker = WireLib.RegisterPlayerTable()
}, self)
end
@thevurv
thevurv / checkargtype.lua
Created August 14, 2021 21:16
A lua function that checks that arguments of correct types. Supports vararg amount of types and mimics native lua errors exactly.
local function error_fmt(level, msg, ...)
error( string.format(msg, ...), level + 1 )
end
local function checkargtype(val, argnum, func_name, ...)
local expected_msg = {}
local t = type(val)
local count = select('#', ...)
for i = 1, count do
local expected = select(i, ...) or "nil"
@thevurv
thevurv / id_alloc_fast.lua
Last active July 13, 2021 00:38
Faster? id allocation without recursion
local MaxConcurrent = 512 -- Max concurrent active streams
local TopID = 0 -- Current top-most id.
local IsSequential = true -- Boost for initial creation when no IDs have been dropped.
local OccupiedCount = 0
local Occupied = {}
local function register(id)
Occupied[id] = true
@thevurv
thevurv / id_alloc.lua
Created July 13, 2021 00:27
Small but Inefficient ID alloc
local MaxConcurrent = 512 -- Max concurrent active objects
local TopID = 0 -- Current top-most id.
local OccupiedCount = 0
local Occupied = {}
local function allocID(n)
if OccupiedCount >= MaxConcurrent then return end
local new = (n or TopID) % MaxConcurrent + 1
if Occupied[new] then
@thevurv
thevurv / sf_globalaccess.lua
Last active June 7, 2021 00:24
Adding _G access to starfall safely
local function addModule(name, exec)
if not SF.Modules then error("SF Modules table doesn't exist!") end
SF.Modules[name] = {
["injected"] = {init = exec()}
}
end
local function reloadSFEditor()
pcall(function()
if SF.Editor.initialized then