Skip to content

Instantly share code, notes, and snippets.

View hanxi's full-sized avatar
:octocat:
Happy Coding!!!

涵曦 hanxi

:octocat:
Happy Coding!!!
View GitHub Profile
@hanxi
hanxi / HXProtHandler.lua
Created August 26, 2013 06:35
单消息多处理函数的实现.注册消息处理函数时可提供优先执行函数列表(即在优先执行函数列表中的函数先于正在注册的函数).
--[[=============================================================================
# FileName: HXProtHandler.lua
# Desc: 单个消息多个处理函数带有优先级的实现
# Author: hanxi
# Email: hanxi.com@gmail.com
# HomePage: http://hanxi.cnblogs.com
# Version: 0.0.1
# LastChange: 2013-08-26 11:42:37
# History: 添加优先级冲突检测
=============================================================================]]
@hanxi
hanxi / point_to_menber_func.cpp
Created August 31, 2013 17:02
类成员函数指针指向类成员
#include <iostream>
using namespace std;
class A {
public:
A() {
q=&A::funcA;
cout << "q=" << q << endl;
//(this ->* ((A*)this)->A::q) ();
@hanxi
hanxi / deepcopy.lua
Created September 29, 2013 03:55 — forked from Deco/deepcopy.lua
--[[ deepcopy.lua
Deep-copy function for Lua - v0.2
==============================
- Does not overflow the stack.
- Maintains cyclic-references
- Copies metatables
- Maintains common upvalues between copied functions (for Lua 5.2 only)
TODO
#include "lua.h"
#include "lauxlib.h"
#include <stdio.h>
int
dylib_add(lua_State* L) {
int a = lua_tonumber(L,1);
int b = lua_tonumber(L,2);
int c = a+b;
@hanxi
hanxi / fork_fork.c
Last active August 29, 2015 13:57
子进程的使用,父进程根据signal监听子进程的退出。预防僵尸进程的两种方法。
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
if ((pid = fork()) < 0)
--[[=============================================================================
# FileName: 2048.lua
# Desc: lua console 2048
# Author: hanxi
# Email: hanxi.info@gmail.com
# HomePage: http://www.hanxi.info
# Version: 0.0.1
# LastChange: 2014-04-28 11:05:09
# History:
=============================================================================]]
@hanxi
hanxi / setconst.lua
Created June 5, 2014 14:06
将lua配置表设置成只读
local rawnext = next
function next(t,k)
local m = getmetatable(t)
local n = m and m.__next or rawnext
return n(t,k)
end
function pairs(t) return next, t, nil end
function readonly(t)
local proxy = {}
@hanxi
hanxi / createtable.sql
Created July 2, 2014 08:54
新浪sae搭建游戏分数排行榜
CREATE TABLE `ScoreRank` (
`Name` varbinary(64) NOT NULL,
`Score` int(11) DEFAULT NULL,
`Level` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`Name`,`Level`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- bare-bones luac in Lua
-- usage: lua luac.lua file.lua file.out
local out=arg[1]..".out"
if arg[2]~=nil then out=arg[2] end
f=assert(io.open(out,"wb"))
assert(f:write(string.dump(assert(loadfile(arg[1])))))
assert(f:close())
@hanxi
hanxi / testabc.lua
Last active August 29, 2015 14:05
a+b=c a,b,c都是三位数且不重复
local tostring = tostring
local tonumber = tonumber
local ssub = string.sub
local sformat = string.format
local tconcat = table.concat
local tinsert = table.insert
local si={1,2,3,4,5,6,7,8,9}
function printsi(si)
print(tconcat(si))