Skip to content

Instantly share code, notes, and snippets.

View cloudwu's full-sized avatar

云风 cloudwu

View GitHub Profile
@cloudwu
cloudwu / utf16.lua
Created October 22, 2020 07:54
lua UTF16 BE lib
local utf16 = {}
-- Big Endian
function utf16.toutf8(s)
local surrogate
return (s:gsub("..", function(utf16)
local cp = string.unpack(">H", utf16)
if (cp & 0xFC00) == 0xD800 then
surrogate = cp
@cloudwu
cloudwu / Localization.cs
Last active September 28, 2020 03:01
config.csv for MOO UCP
public void LoadFile(string path)
{
try
{
string csvText = AssetManager.Get().Resource<string>(path);
string[,] array = CSVReader.SplitCsvGrid(csvText);
// Fix bug of UCP here
for (int i = 2; i < array.GetUpperBound(0); i++)
{
for (int j = 1; j < array.GetUpperBound(1); j++)
@cloudwu
cloudwu / hashcompare.lua
Last active May 28, 2020 10:54
Compare some hash function for lua table implementation
--[[
370104 words from https://github.com/dwyl/english-words/blob/master/words_alpha.txt
3/4 5/8 7/8 9/16 11/16 13/16 15/32 17/32 19/32 21/32
(h<<5) + (h>>2) + x (3)84874 (4)81670 (4)113326 (4)80336 (2)96169 (5)111520 (4)125243 (3)79309 (4)87762 (5)95643
(h<<4) + (h>>3) + x (2)84819 (1)81351 (3)113283 (5)80439 (3)96264 (2)111197 (3)125200 (4)79486 (2)87582 (2)95430
(h<<5) - (h>>2) + x (1)84464 (2)81428 (2)113108 (2)80201 (4)96464 (4)111469 (1)125052 (2)79222 (3)87666 (3)95466
(h<<4) - (h>>3) + x (4)85050 (3)81587 (1)113084 (1)80112 (1)96131 (1)111134 (2)125185 (1)79163 (1)87361 (1)95239
((h + x) * 0xAAAB) >> 3 (5)85143
@cloudwu
cloudwu / lseed.c
Created March 25, 2020 10:32
Change seed for lua 5.3
/*
Only for lua 5.3
You can use lua_changeseed(L, seed) to change a seed for a lua VM.
lua_State *L = luaL_newstate();
lua_changeseed(L, myseed);
*/
#include "lstate.h"
@cloudwu
cloudwu / cacheserver.lua
Created July 5, 2019 09:41
Unity cache server
local skynet = require "skynet"
local socket = require "skynet.socket"
local db_path = assert(skynet.getenv "cache_db") .. "/"
local mode = (...) or "main"
local function tohex(c)
return string.format("%02x", c:byte())
end
@cloudwu
cloudwu / bgfxcsgen.lua
Created June 27, 2019 03:13
Generate c shape interface for bgfx
local idl = require "idl"
do
local doxygen = require "doxygen"
local source = doxygen.load "bgfx.idl"
local f = assert(load(source, "bgfx.idl" , "t", idl))
f()
local codegen = require "codegen"
codegen.nameconversion(idl.types, idl.funcs)
@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