Skip to content

Instantly share code, notes, and snippets.

View starwing's full-sized avatar

Xavier Wang starwing

  • Chengdu
View GitHub Profile
@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 / Makefile
Created July 5, 2013 23:18
a kernel module used to read chipid of cubieboard
obj-m := chipid.o
@starwing
starwing / vararg.c
Last active May 4, 2021 07:45
A vararg module compatible with Lua 5.3
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
static lua_Integer posrelat(lua_Integer pos, size_t len) {
if (pos >= 0) return pos;
else if (0u - (size_t)pos > len) return 0;
else return (lua_Integer)len + pos + 1;
}
#ifndef lua_bufflib_h
#define lua_bufflib_h
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
#define BUFFER_LIBNAME "buffer"
@starwing
starwing / build_freeglut.bat
Last active December 13, 2015 17:39
Build freeglut with MinGW
@rd /s /q obj 2>nul
@md obj
@cd obj
gcc -O2 -c -DFREEGLUT_EXPORTS ../src/*.c -I../include
gcc -mdll -o ../freeglut32.dll *.o^
-Wl,--enable-stdcall-fixup,--out-implib,libfreeglut32.a^
-lopengl32 -lgdi32 -lwinmm
gcc -O2 -c -DFREEGLUT_STATIC ../src/*.c -I../include
@starwing
starwing / .gitignore
Last active December 12, 2015 10:09
A script from Lua 5.1 to compile Lua with MSVC, modified to fit Lua 5.2.
Lua52/
*.a
@starwing
starwing / install-lua.cmd
Created July 13, 2012 03:32
script to install Lua on Windows.
@set LUAVER=lua52
@if "%1x" == "x" (
set LUADIR=D:\%LUAVER%\
) else set LUADIR=%1\%LUAVER%\
@echo install Lua to %LUADIR% ...
@echo create directories ...
@mkdir %LUADIR% 2>nul
@mkdir %LUADIR%include 2>nul
@mkdir %LUADIR%clibs 2>nul
@mkdir %LUADIR%lua 2>nul
@starwing
starwing / .gitignore
Created June 1, 2012 02:54
tokentools temporary repository
*.exe
*.dll
tags*
objs
@starwing
starwing / normpath.c
Last active July 7, 2024 13:05
a path normalize algorithm
#include <stdio.h>
#include <string.h>
#define COMP_MAX 50
#define ispathsep(ch) ((ch) == '/' || (ch) == '\\')
#define iseos(ch) ((ch) == '\0')
#define ispathend(ch) (ispathsep(ch) || iseos(ch))
char *normpath(char *out, const char *in) {
@starwing
starwing / .gitignore
Created May 20, 2012 19:34
a path maintain module for lua
test
tags*
*.exe
*.dll
*.obj
*.so
*.o