Skip to content

Instantly share code, notes, and snippets.

View edubart's full-sized avatar

Eduardo Bart edubart

View GitHub Profile
@edubart
edubart / debugmem.lua
Last active December 18, 2018 23:23
Debug Lua Mem
function debug_refs()
local reftable = {}
local function trace_refs(o, src, src2, src3)
local typ = type(o)
if typ == 'number' or typ == 'boolean' or typ == 'string' or typ == 'thread' or typ == 'nil' then return end
if o == debug_refs or o == reftable or o == trace_refs then return end
if reftable[o] then return end
reftable[o] = true
if src3 then
src = string.format('%s%s%s', src, src2, tostring(src3))
@edubart
edubart / gen_lua_functions.lua
Created January 28, 2019 21:51
Generate lua functions from lua environment
local function get_args(fun)
local args = {}
local hook = debug.gethook()
local argHook = function( ... )
local info = debug.getinfo(3)
if 'pcall' ~= info.name then return end
for i=1,100 do
local name, value = debug.getlocal(2, i)
if name == nil or name:match('%(') then
package="lbc"
version="20180729-1"
source = {
url = "http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/lbc-100.tar.gz",
md5 = "e5db9e3d0cc28099e0b3b6018939b43e",
dir = "lbc-100"
}
description = {
summary = "A simple arbitrary precision library",
detailed = [[
package = "lcomplex"
version="20180729-1"
source = {
url = "http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/lcomplex-100.tar.gz",
dir = "lcomplex-100",
md5 = "ba3c9babf127cf1a313453bcabaf2a73"
}
description = {
-- import SDL headers
!!cdefine 'SDL_DISABLE_IMMINTRIN_H'
!!cinclude '<SDL2/SDL.h>'
!!linklib 'SDL2'
-- import SDL structures
local SDL_Event = @record {
type: uint32,
padding: array<byte, 56>
}
/* This file was auto generated by Euluna. */
/* Compile command: gcc -pipe -std=c99 -fno-strict-aliasing -rdynamic -lm -Wall -Wextra -Wno-incompatible-pointer-types -g -lSDL2 -o "euluna_cache/playground/snake" "euluna_cache/playground/snake.c" */
/* Compile hash: 2waXGLampSxudc7zNvTWHfYvFPNb */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#define EULUNA_NORETURN __attribute__((noreturn))
@edubart
edubart / raytrace.lua
Created May 31, 2019 22:00
euluna raytracer test
!!strict
-- optimize for performance
!!cflags '-O3 -ffast-math -march=native -fno-plt -flto -fopenmp -rdynamic -g'
!!ldflags '-flto'
--------------------------------------------------------------------------------
-- SDL
-- import SDL headers
@edubart
edubart / inheretance_example.cpp
Created February 3, 2020 13:53
inheretance_example.cpp
#include <stdint.h>
#include <stdio.h>
struct Shape {
Shape(int64_t x, int64_t y): x(x), y(y) {}
virtual int64_t area() {return 0;}
int64_t x, y;
};
struct Rectangle : public Shape {
--------------------------------------------------------------------------------
-- meta programming utilities for inheritance
##[[
local function check_record_type(sym)
staticassert(sym and sym.type and sym.type:is_type() and sym.value:is_record(),
"symbol '%s' must be a type holding a record type", sym.name)
return sym.value
end
@edubart
edubart / c2nelua.lua
Last active April 5, 2020 00:37
c2nelua rudimentar experiment
local re = require 'relabel'
local file = require 'pl.file'
local stringx = require 'pl.stringx'
local grammar = [[
body <- {| line+ |}
line <- (extern / anyline)
anyline <- linerest
linerest<- [^;]* ';' sp
sp <- %s*