Skip to content

Instantly share code, notes, and snippets.

@szakharchenko
szakharchenko / gdb-backtrace-when-compiled-with-O0
Last active June 13, 2020 08:26
Lua 5.4.0-rc5 low memory segfault reproduction files
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7cdef98 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff7cdef98 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff7ce1c98 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff7ce2f25 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007ffff7ce3f8f in realloc () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x000055555557f73e in l_alloc (ud=0x0, ptr=0x5555555a28c0, osize=544, nsize=1536) at lauxlib.c:1009
#5 0x000055555556974d in luaM_realloc_ (L=0x5555555a2268, block=0x5555555a28c0, osize=544, nsize=1536) at lmem.c:166
#6 0x0000555555562b47 in luaD_reallocstack (L=0x5555555a2268, newsize=96, raiseerror=1) at ldo.c:187
@szakharchenko
szakharchenko / prettify-config.el
Created October 17, 2018 05:25
Lua 'prettification' sample
;; Use this, and turn on prettify-symbols-mode in a buffer
;; Isn't easy to disable in mmm-mode, though
(add-hook
'lua-mode-hook
(lambda ()
(setq prettify-symbols-alist
'(
("function" . 955)
("local" . 8466)
("==" . 8801)
@szakharchenko
szakharchenko / render.js
Created June 20, 2018 14:11
Trivial PhantomJS renderer sample
var page = require('webpage').create();
page.open("simple.html", function (status) {
if (status !== "success")
{
console.log("Unable to load");
phantom.exit(1);
}
else
{
page.render("simple.png");
@szakharchenko
szakharchenko / gc_test.lua
Created April 19, 2018 08:54
Obtaining a reference to an already finalized object from Lua
-- Demonstration of how a reference to an already finalized object
-- can be constructed entirely from Lua. Compatible with Lua 5.1..5.3.
-- Helper to create a value calling a specific callback when it is GCd.
local gc_handler
if newproxy then
gc_handler=function (callback)
local ret=newproxy(true)
getmetatable(ret).__gc=callback