涓嬮潰鏄竴涓狶UA闈㈠悜瀵硅薄鍐欐硶闈炲父甯歌鐨勫啓娉曘?br />
Bird = {
color = {};canFly = true
}
function Bird:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
self.color = {}
return o
end
娉ㄦ剰錛岃繖閲孊ird綾繪湁涓や釜灞炴э紝1涓〃錛?涓槸鍩烘湰綾誨瀷錛岀劧鍚庝笂嫻嬭瘯浠g爜錛圲tils綾誨彧鏄畝鍗曠殑灝佽綾伙紝鍙互鑷繁瀹炵幇涓涓級
local A = Bird:new()
LoggerUtils:debug("------------------------------鍘熷鍊?----------------------------------");
LoggerUtils:debug("Bird canFly:" .. StringUtils.boolean2string(A.canFly));
LoggerUtils:debug("Bird color:");
CommonUtils.printTable(Bird.color)
LoggerUtils:debug("a canFly:" .. StringUtils.boolean2string(A.canFly));
LoggerUtils:debug("a color:");
CommonUtils.printTable(A.color)
--鏀瑰彉A鐨勫睘鎬?br />
A.canFly = false
A.color[1] = "red"
A.color[2] = "blue"
A.color[3] = "green"
LoggerUtils:debug("------------------------------A鏀瑰彉鍚?---------------------------------");
LoggerUtils:debug("Bird canFly:" .. StringUtils.boolean2string(Bird.canFly));
LoggerUtils:debug("Bird color:");
CommonUtils.printTable(Bird.color)
LoggerUtils:debug("A canFly after change:" .. StringUtils.boolean2string(A.canFly));
LoggerUtils:debug("A color after chagne:");
CommonUtils.printTable(A.color)
LoggerUtils:debug("-------------------------------B鐨勫?---------------------------------");
local B = Bird:new()
LoggerUtils:debug("B canFly:" .. StringUtils.boolean2string(B.canFly));
LoggerUtils:debug("B color:");
CommonUtils.printTable(B.color)
浠g爜鎵ц緇撴灉錛?br />2014-12-29 11:20:40,690 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: ------------------------------鍘熷鍊?----------------------------------
2014-12-29 11:20:40,690 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird canFly:true
2014-12-29 11:20:40,691 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird color:
2014-12-29 11:20:40,691 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: a canFly:true
2014-12-29 11:20:40,691 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: a color:
2014-12-29 11:20:40,691 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: ------------------------------A鏀瑰彉鍚?---------------------------------
2014-12-29 11:20:40,691 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird canFly:true
2014-12-29 11:20:40,691 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird color:
2014-12-29 11:20:40,692 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 1:red
2014-12-29 11:20:40,692 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 2:blue
2014-12-29 11:20:40,692 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 3:green
2014-12-29 11:20:40,692 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: A canFly after change:false
2014-12-29 11:20:40,692 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: A color after chagne:
2014-12-29 11:20:40,693 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 1:red
2014-12-29 11:20:40,693 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 2:blue
2014-12-29 11:20:40,695 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 3:green
2014-12-29 11:20:40,695 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: -------------------------------B鐨勫?---------------------------------
2014-12-29 11:20:40,695 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: B canFly:true
2014-12-29 11:20:40,695 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: B color:
2014-12-29 11:20:40,695 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 1:red
2014-12-29 11:20:40,695 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 2:blue
2014-12-29 11:20:40,696 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 3:green
鍙戠幇紲為┈闂浜嗗悧錛?br />褰揂鐨勭被鍨嬩負琛ㄧ殑灞炴olor鏀瑰彉鏃訛紝鍘熷綾葷殑color灞炴т篃鏀瑰彉浜嗭紝鍚屾椂榪欎釜鏀瑰彉涔熷獎鍝嶅埌鏂板緩鐨凚錛岃岀被鍨嬩負鍩烘湰綾誨瀷鐨勫睘鎬anFly灝辨病鏈夎繖涓棶棰樸?br />鎴戠殑瑙e喅鏂規硶鏄柊澧炰竴涓猻et鏂規硶錛?br />function Bird:setColor(color)
self.color = color
end
鐒跺悗淇敼鏀瑰彉灞炴х殑鏂瑰紡錛?br />local color ={}
color[1] = "red"
color[2] = "blue"
color[3] = "green"
A:setColor(color)
杈撳嚭緇撴灉錛?br />2014-12-29 11:31:58,648 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: ------------------------------鍘熷鍊?----------------------------------
2014-12-29 11:31:58,648 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird canFly:true
2014-12-29 11:31:58,649 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird color:
2014-12-29 11:31:58,649 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: a canFly:true
2014-12-29 11:31:58,649 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: a color:
2014-12-29 11:31:58,649 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: ------------------------------A鏀瑰彉鍚?---------------------------------
2014-12-29 11:31:58,649 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird canFly:true
2014-12-29 11:31:58,650 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: Bird color:
2014-12-29 11:31:58,650 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: A canFly after change:false
2014-12-29 11:31:58,650 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: A color after chagne:
2014-12-29 11:31:58,650 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 1:red
2014-12-29 11:31:58,650 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 2:blue
2014-12-29 11:31:58,650 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: 3:green
2014-12-29 11:31:58,651 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: -------------------------------B鐨勫?---------------------------------
2014-12-29 11:31:58,651 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: B canFly:true
2014-12-29 11:31:58,653 [main] DEBUG server.app.game.util.LoggerUtils:34 - LUA: B color:
鍙﹀鍚屼簨涓涓В鍐蟲柟娉曟洿綆鍗曪紝鐩存帴淇敼new()鏂規硶錛屽叾瀹冪殑鍦版柟閮戒笉鐢ㄦ敼錛?br />function Bird:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
o.color = {}
return o
end
榪欎釜闂鍩烘湰涓婄綉涓婄殑紺轟緥璨屼技閮芥病鎻愬埌錛屾垜璇葷殑涔﹂噷涔熸病鏈夛紝瀹為檯璋冭瘯榪囩▼涓墠鍙戠幇鐨勶紝浼氶犳垚鏂板垱寤虹殑綾婚噷浼氭湁涓嶈鏈夌殑灞炴э紝姣旇緝铔嬬柤銆?br />鍏蜂綋鍘熷洜涓嶄簡瑙o紝鏈夋湪鏈夌瓛瀛愭寚鏁欎竴涓嬶紵欏轟究闂棶榪欎袱縐嶆柟娉曞摢縐嶆洿濂斤紵
]]>