Skip to content

Instantly share code, notes, and snippets.

View sharpobject's full-sized avatar

Robert Burke sharpobject

View GitHub Profile
@sharpobject
sharpobject / paths.lua
Created July 14, 2020 07:43
Find all the paths to an object hopefully
local debug = debug
local coroutine = coroutine
local type = type
local next = next
local pairs = pairs
local package = package
local rawequal = rawequal
-- todo: lightuserdata?
local all_types = {
local debug = debug
local coroutine = coroutine
local type = type
local next = next
local pairs = pairs
local package = package
-- todo: lightuserdata?
local all_types = {
1,
@sharpobject
sharpobject / revcomp.lua-3.lua
Last active May 9, 2020 12:52
reverse-complement lua program for The Computer Language Benchmarks Game
-- The Computer Language Benchmarks Game
-- https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
-- contributed by Mike Pall (with ideas from Rici Lake)
-- modified for 5.3 by Robin
-- multithread by sharpobject
-- arg[2] = worker id if we are a worker, absent if we are the main process
local is_worker = arg[2]
local always_output = is_worker == "1"
@sharpobject
sharpobject / main.lua
Created March 23, 2020 11:37
render in a thread
local ffi = require("ffi")
ffi.cdef[[
int SDL_GL_MakeCurrent(void* window,void* context);
void* SDL_GL_GetCurrentContext(void);
void* SDL_GL_GetCurrentWindow(void);
]]
function love.load()
@sharpobject
sharpobject / co_wrap.lua
Created March 1, 2020 01:33
Coroutines on coroutines
local co_stack = {}
local co_running = {}
local n_cos = 0
local real_yield = coroutine.yield
local real_resume = coroutine.resume
local real_status = coroutine.status
local real_create = coroutine.create
local co_wrap_resume
local co_wrap_loop
local co_stack = {}
local co_running = {}
local n_cos = 0
local real_yield = coroutine.yield
local real_resume = coroutine.resume
local real_status = coroutine.status
local real_create = coroutine.create
local co_wrap_resume
local co_wrap_loop
Janet 1.7.0-f7ee8bd Copyright (C) 2017-2019 Calvin Rose
janet:1:> (defn my_fn [] (for i 0 10 (yield i)))
<function my_fn>
janet:2:> (defn coroutine-clone [co] (unmarshal (marshal co make-image-dict) load-image-dict))
<function coroutine-clone>
janet:3:> (def a (coro (my_fn)))
<fiber 0x00580A80>
janet:4:> (resume a)
0
janet:5:> (resume a)
@sharpobject
sharpobject / atkin.lua
Created February 11, 2020 08:24
luajit 2.1.0-beta3 segfault :(
local function arr_to_set(t)
local ret = {}
for k,v in ipairs(t) do
ret[v] = true
end
return ret
end
local check_31 = arr_to_set{1,13,17,29,37,41,49,53}
local check_32 = arr_to_set{7,19,31,43}
local bylen = {}
for i=1,99 do bylen[i] = {} end
for word in io.lines("/usr/share/dict/words") do
if #word % 2 == 0 then
local bucket = bylen[#word]
bucket[#bucket+1] = word:lower()
end
end
for i=2,99,2 do
@sharpobject
sharpobject / CircleLineSegment.lua
Last active October 21, 2016 02:00
Collision functions for closed circles, lines, and closed segments. When a collision is detected, a point contained in both objects is returned.
function SegmentCircleIntersect(a, b, c)
local ac2 = (c.x - a.x)^2 + (c.y - a.y)^2
local cr2 = c.r * c.r
if ac2 <= cr2 then
return a
end
local bc2 = (c.x - b.x)^2 + (c.y - b.y)^2
if bc2 <= cr2 then
return b