Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am bakpakin on github.
  • I am calsrose (https://keybase.io/calsrose) on keybase.
  • I have a public key ASD62xnhgH6qEJAsaF1kQTKnIh0fDV-TGC_zX43VZpx7QAo

To claim this, I am signing this object:

SPECIALS['lua'] = function(ast, scope, parent)
table.insert(parent, {leaf = ast[2], ast = ast})
end
@bakpakin
bakpakin / fennel-lua.lua
Created January 26, 2019 00:44
New code injection special
-- (lua "print('hello!')") -> prints hello, evaluates to nil
-- (lua "print 'hello!'" "10") -> prints hello, evaluates to the number 10
-- (lua nil "{1,2,3}") -> Evaluates to a table literal
SPECIALS['lua'] = function(ast, scope, parent)
assertCompile(#ast == 2 or #ast == 3,
"expected 2 or 3 arguments in 'lua' special form", ast)
if ast[2] ~= nil then
table.insert(parent, {leaf = tostring(ast[2]), ast = ast})
end
if #ast == 3 then
@bakpakin
bakpakin / gist:c0295eb52ec1bcca1e3b353d154ed23b
Created March 12, 2019 18:32
Indented Fennel example by fennel.vim
(fn line-iter [packets]
(var buf "")
(fn recur []
(local (residual rest) (: buf :match "^(.*)\r\n(.*)$"))
(if residual
(do (set buf rest) residual)
(let [packet (packets)]
(when packet
(set buf (.. buf packet))
(recur))))))
@bakpakin
bakpakin / janetsh.rc
Created May 25, 2019 02:10
janetsh rc
(import shlib)
(defn ansi
"Take a string made by concatenating xs and colorize it for an ANSI terminal."
[code & xs]
(string "\e[" code "m" ;xs "\e[0m"))
(defn cmd
"Run a quick command and strip trailing newline."
[s]
@bakpakin
bakpakin / diff.patch
Created June 6, 2019 19:34
Fennel include patch
diff --git a/fennel.lua b/fennel.lua
index 56ee209..a951d5f 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -422,6 +422,9 @@ local function makeScope(parent)
symmeta = setmetatable({}, {
__index = parent and parent.symmeta
}),
+ includes = setmetatable({}, {
+ __index = parent and parent.includes
static JanetFunction *global_cb = NULL;
Janet register_callback(int32_t argc, Janet *argv) {
janet_fixarity(argc, 1);
JanetFunction *cb = janet_getfunciton(argv, 0);
global_cb = cb;
// Make sure the callback is not garbage collected while waiting
janet_gcroot(argv[0]);
return janet_wrap_nil();
}
@bakpakin
bakpakin / janet.hpkg
Created September 4, 2019 02:53
hermes janet package
core_modules = unpack_url(
url="https://github.com/buildpackagedeploy/hermes-core/archive/4f92d8aaa001406e58513929710027bc4b733cf2.tar.gz",
hash="sha256:db931edc4ddf71a8d749a09f14ed5d771f7099b898273176111452c4b9700983",
)
bootstrap_env = load_module(core_modules, "bootstrap.hpkg").bootstrap_env
janet_src = fetch_url(
url="https://github.com/janet-lang/janet/archive/v1.2.0.tar.gz",
hash="sha256:e824ee2da7dffab10bb7ce28917b57a82df82eebf713ad2bbb74ed7be36bd4f4"
@bakpakin
bakpakin / fix.diff
Created September 7, 2019 01:56
Fix ambiguous Lua code emitted from Fennel
diff --git a/fennel.lua b/fennel.lua
index c079085..dd7252f 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -825,7 +825,8 @@ local function keepSideEffects(exprs, chunk, start, ast)
if se.type == 'expression' and se[1] ~= 'nil' then
emit(chunk, ('do local _ = %s end'):format(tostring(se)), ast)
elseif se.type == 'statement' then
- emit(chunk, tostring(se), ast)
+ local code = tostring(se)
@bakpakin
bakpakin / fix.diff
Created September 20, 2019 04:14
Fix for bad stacktraces in fennel.
diff --git a/fennel.lua b/fennel.lua
index 8c79320..58341df 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -2057,7 +2057,8 @@ local function traceback(msg, start)
local level = start or 2 -- Can be used to skip some frames
local lines = {}
if msg then
- table.insert(lines, msg)
+ local stripped = msg:gsub('^[^:]*:%d+:%s+', 'runtime error: ')