Skip to content

Instantly share code, notes, and snippets.

View edubart's full-sized avatar

Eduardo Bart edubart

View GitHub Profile
##[=[
linklib 'lua'
cinclude '<lua.h>'
cinclude '<lauxlib.h>'
cinclude '<lualib.h>'
local ccdefs = require 'nelua.ccompiler'.get_cc_defines('<lua.h>')
static_assert(ccdefs.LUA_VERSION_NUM == 504, 'unsupported Lua version')
local c2nelua = {
['double'] = float64,
@edubart
edubart / arduino-gameoflife.lua
Created September 17, 2020 22:31
Arduino Game of Life in Nelua
require 'arduino'
-- user configurable defines
local CELL_SIZE: cint <comptime> = 4 -- the height and width of each cell
local DELAY: cint <comptime> = 50 -- number of milliseconds delay between the display of each generation
-- end of user configurable defines
local ROWS: cint <comptime> = (DISPLAY_HEIGHT // CELL_SIZE)
local COLUMNS: cint <comptime> = (DISPLAY_WIDTH // CELL_SIZE)
@edubart
edubart / luacov-scm-1.rockspec
Created August 19, 2020 12:06
luacov rockspec for lua 5.4
package = "luacov"
version = "scm-1"
source = {
url = "git+https://github.com/keplerproject/luacov.git",
}
description = {
summary = "Coverage analysis tool for Lua scripts",
detailed = [[
LuaCov is a simple coverage analysis tool for Lua scripts.
When a Lua script is run with the luacov module, it
@edubart
edubart / xt_entropy.c
Created May 9, 2020 15:25
Network traffic entropy calculator in kernel
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <generated/autoconf.h>
#include <linux/kernel.h>
#include <linux/module.h>
@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*
--------------------------------------------------------------------------------
-- 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 / 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 {
@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
/* 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))
-- 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>
}