Skip to content

Instantly share code, notes, and snippets.

View starwing's full-sized avatar

Xavier Wang starwing

  • Chengdu
View GitHub Profile
@starwing
starwing / .gitignore
Last active December 13, 2023 07:00
lua lexer - a Lua C module implementing a lexer for Lua.
*.dll
*.gcda
*.gcno
*.gcov
*.exp
*.lib
*.pdb
@starwing
starwing / builtin.c
Last active March 30, 2016 20:08
A Lua module loads symbol from global namespace
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#include <string.h>
#define LUA_OFSEP "_"
#define LUA_IGMARK "-"
#define LUA_POF "luaopen_"
@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>
@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 / 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 / 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>
#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);
#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;
@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"
@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