Skip to content

Instantly share code, notes, and snippets.

View starwing's full-sized avatar

Xavier Wang starwing

  • Chengdu
View GitHub Profile
@starwing
starwing / Makefile
Created July 5, 2013 23:18
a kernel module used to read chipid of cubieboard
obj-m := chipid.o
@starwing
starwing / hashtable.c
Last active December 30, 2015 08:19
A simple hash table inspired from Lua's ltable.c
#include "hashtable.h"
#include <stdlib.h>
#include <string.h>
#define ht_isfree(node) ((node)->key == HT_NOKEY)
#define ht_keysize(ht, n) (sizeof(HashKey)+ht->vsize)*(n)
@starwing
starwing / cdecl_parser.lua
Created February 22, 2014 13:32
a C declaration parser written in Lua
local parse_declare
local function parse_typespec(decl, s, pos)
-- typespec: cv_decl* spec cv_decl*
-- cv_decl: 'const' | 'volatile'
while true do
local spec, newpos = s:match("^%s*([%w_]+)%s*()", pos)
if not spec then break end
if spec == "const" then
@starwing
starwing / lua-nanovg.c
Last active August 29, 2015 13:59
NanoVG binding for Lua
#define LUA_LIB
#include "lbind.h"
#include "gl_2_0_core.h"
static int opengl_loaded = 0;
#define NANOVG_GL2_IMPLEMENTATION
#include "nanovg/src/nanovg_gl.h"
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "../src/nanovg.h"
#define NANOVG_GL2_IMPLEMENTATION
#include "../src/nanovg_gl.h"
/*#include "../example/perf.h"*/
struct Lyrics {
int time;
#include "acllib.h"
#include <stdio.h>
static void draw(const char *s, int x, int y) {
POINT points[1000];
setPenStyle(PEN_STYLE_NULL);
while (*s) {
if (*s == 'M') {
int i = 0, pos;
sscanf(s, "M %ld,%ld %n", &points[i].x, &points[i].y, &pos);
@starwing
starwing / lunzip.c
Last active March 25, 2016 09:19
lunzip - A Lua module that use minizip to extra information from a zip file.
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include "minizip/unzip.h"
#include "minizip/ioapi_mem.h"
#include <string.h>
@starwing
starwing / kit.h
Last active March 25, 2016 09:26
kit - a simple type system.
/* kit - a simple type system
* Xavier Wang (c) 2015, MIT license
*
* kit is a simple library for a type system, inspired by llib[1].
* it can be used to simplifiy developing. kit offers:
* - ref-counted object/array
* - pointer-compare symbol
* - array of refs (refarray) support
* - a object pool implement
* - a hashtable implement
@starwing
starwing / timer.lua
Created November 18, 2015 08:56
A pure Lua timer implement for LuaJIT
local sleep, get_time
local math_floor = math.floor
if not jit then -- not LuaJIT?
return require "timer.c"
elseif jit.os == "Windows" then
local ffi = require "ffi"
ffi.cdef [[
void __stdcall Sleep(unsigned dwMilliseconds);
unsigned __stdcall GetTickCount(void);
@starwing
starwing / luatcl.c
Last active December 14, 2015 16:52
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <Tcl.h>
#include <ctype.h>
#include <string.h>