Skip to content

Instantly share code, notes, and snippets.

View cloudwu's full-sized avatar

云风 cloudwu

View GitHub Profile
@cloudwu
cloudwu / ecs.lua
Created December 3, 2017 14:22
Lua ECS
local core = require "ecs.core"
local ecs = {}
local entities = {} -- all Entities, eid -> entity
local entity_id = 0
ecs.entities = entities
-- cset: component set
local cset = { __mode = "kv" }
local shadowcopy = {}
local weak = { __mode = "k" }
local NIL = {}
local queue = setmetatable({}, weak) -- object -> queue
local map = setmetatable({}, weak) -- copy -> { object = obj, values = {} }
local direct_mt = {
__index = function(t,k)
@cloudwu
cloudwu / pdx.lua
Created July 7, 2017 01:54
paradox file parser
local pdx = {}
do
local lpeg = require "lpeg"
local P = lpeg.P
local S = lpeg.S
local R = lpeg.R
local C = lpeg.C
@cloudwu
cloudwu / lclonetable.c
Last active May 21, 2021 08:42
Clone a lua table
// gcc -o clonetable.so --shared lclonetable.c -I$(LUAINCLUDE)
#include <lobject.h>
#include <ltable.h>
#include <lgc.h>
#include <lstate.h>
#include <lauxlib.h>
#include <lualib.h>
#include <lua.h>
#include <string.h>
@cloudwu
cloudwu / pimpl.cpp
Last active July 3, 2017 10:51
My version of pimpl
// My version of pimpl ([email protected])
// See http://en.cppreference.com/w/cpp/language/pimpl
#include <iostream>
// interface (widget.h)
class widget {
struct impl;
public:
static widget* create(int); // replacement of new
@cloudwu
cloudwu / ttfont.c
Last active November 28, 2022 22:43
sample for stb truetype
#include <stdio.h>
#define HEIGHT 24
#define STB_TRUETYPE_IMPLEMENTATION
#define STBTT_STATIC
// gcc -Wall -Wno-unused-function -g ttfont.c -o ttfont.exe
// https://github.com/nothings/stb/blob/master/stb_truetype.h
#include "stb_truetype.h"
@cloudwu
cloudwu / luavector.c
Created February 21, 2017 03:46
Direct access vector in lua from C
#include <lua.h>
#include <lauxlib.h>
#include <ltable.h>
#include <lstate.h>
#include <lobject.h>
#include <stdio.h>
#include <string.h>
#define MAGIC_VECTOR 1.23456789
@cloudwu
cloudwu / utf8to16.c
Created January 5, 2017 06:41
A filter for convert utf8 to utf16 in windows.
// Use mingw in windows
// gcc -O2 -o utf8.exe utf8to16.c
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <wchar.h>
static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@cloudwu
cloudwu / compat_alloc.c
Last active May 15, 2020 14:56
A compat memory alloc for lua
// gcc -g -Wall -o alloc alloc.c
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
#include <windows.h>
@cloudwu
cloudwu / lmd5.c
Last active November 30, 2018 13:56
lua md5 mod
/**
* $Id: md5.c,v 1.2 2008/03/24 20:59:12 mascarenhas Exp $
* Hash function MD5
* @author Marcela Ozorio Suarez, Roberto I.
*/
#include <string.h>
//#include "md5.h"