Skip to content

Instantly share code, notes, and snippets.

View cloudwu's full-sized avatar

云风 cloudwu

View GitHub Profile
@cloudwu
cloudwu / luavm.c
Created August 15, 2018 07:48
Lua VM wrapper
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdarg.h>
#include <string.h>
#define ERRLOG 1
#define MSGTABLE 2
#define RETOP 2
@cloudwu
cloudwu / tableunpack.c
Created June 22, 2018 07:19
unpack lua table { ... }
// Unpack lua table create by { ... }
#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>
static int
max_index(lua_State *L, int index) {
int n = lua_rawlen(L, index);
if (n == 0) {
net=5.422477ms,cluster=91.399046ms,cpu=323.263431ms,latency=5.447901ms,time=425.532855ms
login1:00000063 122.286771ms trace gm
login1:00000063 102.904420ms(net=3.207950ms,cluster=0.250590ms,cpu=3.580064ms,time=7.038604ms) call : @./service/agent/player/war_base.lua:363 @./service/agent/player/war_base.lua:130 @./service/agent/agent_lock.lua:62
login1:00000009 3.568610ms request
login1:00000009 3.458540ms(time=0.250590ms) sleep : @./skynet/lualib/skynet/socketchannel.lua:374 @./skynet/service/clusterd.lua:147 @./skynet/service/clusterd.lua:252
center:0000005d 0.250590ms tracecall begin
center:00000056 0.069562ms request
center:00000056 response
center:0000005d tracecall end
login1:00000009 0.011454ms resume
@cloudwu
cloudwu / linalg.c
Last active July 18, 2018 02:03
A linear algebra lua library
// C module for data stack manager
// See below for lua lib wrapper
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MINCAP 128
@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 (cloudwu@gmail.com)
// 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"