This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JAN = 31 | |
daysFeb = {28, 29} | |
MAR = 31 | |
APR = 30 | |
MAY = 31 | |
JUN = 30 | |
JUL = 31 | |
AUG = 31 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// http://www.infoq.com/cn/presentations/node-js-and-real-time-baas-cloud-development-practice?utm_source=infoq&utm_medium=videos_homepage&utm_campaign=videos_row3 | |
// This is a free list to avoid creating so many same object. | |
exports.Freelist = function(name, max, constructor) { | |
this.name = name; | |
this.constructor = constructor; | |
this.max = max; | |
this.list = []; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GameConfig = {} | |
GameConfig.CnfCity= | |
{ | |
[1] = { | |
name = [[testname]], | |
value = 1, | |
list = { | |
{100, 1, 2000, 100, 0, 3, 1, 0, }, | |
{101, 3, 2001, 101, 4, 3, 1, 1, }, | |
{102, 3, 2002, 100, 0, 3, 1, 0, }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = {[2] = 2} | |
local count = 0 | |
for k,v in pairs(t) do | |
count = count + 1 | |
end | |
print(count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local t1 = os.time{year = 2012, month = 12, day = 19, hour = 0, sec = 0} | |
local t2 = os.time{year = 2012, month = 12, day = 19, hour = 23, sec = 59} | |
if (t1 - t2) <= 86400 and | |
(os.date("%d", t1) ~= os.date("%d",t2)) then | |
-- 判断是否有新手目标 | |
print("called") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local key = {} --unique key | |
local mt = {__index = function (t) return t[key] end} | |
function setDefault( t, d ) | |
t[key] = d | |
setmetatable(t, mt) | |
end | |
tab = {x=10, y=20} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setDefault( t, d ) | |
local mt = {__index = function () return d end} | |
setmetatable(t, mt) | |
end | |
tab = {x=10, y=20} | |
print(tab.x, tab.z) | |
setDefault(tab, 0) | |
print(tab.x, tab.z) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Window = {} -- create a namespace | |
-- create the prototype with default values | |
Window.prototype = {x=0, y=0, width=100, height=100} | |
Window.mt = {} --create a metatable | |
--declare the constructor function | |
function Window.new( o ) | |
setmetatable(o, Window.mt) | |
return o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = {} | |
--keep a private access to the original table | |
local _t = t | |
--create proxy | |
t = {} | |
--create metatable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local index = {} | |
-- create private index | |
local mt = { | |
__index = function ( t, k ) | |
print("*access to element " .. tostring(k)) | |
return t[index][k] --access the original table | |
end, | |
__newindex = function ( t, k, v) |
NewerOlder