Skip to content

Instantly share code, notes, and snippets.

View Vurv78's full-sized avatar
😶

Vurv Vurv78

😶
View GitHub Profile
@Vurv78
Vurv78 / 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
@Vurv78
Vurv78 / 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()
@Vurv78
Vurv78 / 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
@Vurv78
Vurv78 / 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"
@Vurv78
Vurv78 / 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
@Vurv78
Vurv78 / 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
@Vurv78
Vurv78 / 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
@Vurv78
Vurv78 / get_open_windows.rs
Last active February 28, 2021 05:40
getOpenWindows function
// Requires winapi-rs.
// Accidentally made this instead of a getOpenPrograms function so just putting it as a gist so it doesn't go to waste.
use winapi::{
um::winuser::{EnumWindows, GetWindowTextW}
};
static mut windows: Vec<String> = Vec::new(); // Use a static because local variables aren't sent to non-closure functions.
unsafe fn getOpenWindows() -> bool {