Skip to content

Instantly share code, notes, and snippets.

View akirayu101's full-sized avatar
🥅
Focusing

Akira Yu akirayu101

🥅
Focusing
  • Bytedance
  • Hangzhou.China
View GitHub Profile
@akirayu101
akirayu101 / hook_timer
Created August 21, 2014 08:55
hook timer
require "src/third/socket.lua"
local time_table = {}
local function hook_timer(o, key, value)
if type(value) == "function" and value ~= "summary" then
local function inner( ... )
time_table[key] = time_table[key] or 0.0
print("in function ",key)
@akirayu101
akirayu101 / class design
Last active August 29, 2015 14:03
lua class design
###lua class设计
* 首先要有super chain, 能够正确无误的调用super方法
* 在create阶段绑定所有的attribute,在create结束后,应该禁用掉一切我外部绑定新attribute的方法,防止别人改掉内省逻辑
* 所有数据成员,应该具有一个初始值设定,对数据对象的生命,应该调用self:define_attribute(key, value, defaultValue)
* 对于回收时刻,应该对每一个attribute,变更成初始状态的值
* 应该支持面向接口集合的delegate,以便进行组合
* 应该对对象内置函数和状态位之间的hook来进行状态位的绑定,不给外部改变状态的机会
* 其他优化点
@akirayu101
akirayu101 / hook_tb.lua
Created July 8, 2014 12:56
method missing
hook_tb = {}
local function hook_index(o, key)
print("get", key)
if type(o["data"][key]) ~= "table" then
return o["data"][key]
else