本文共 1222 字,大约阅读时间需要 4 分钟。
文件 MsgPro.lua
local Player = require "LuaScript/Player"local createPlayer = Player.createPlayerlocal p = createPlayer("asas",2)print(p:getlevel())print(p:getname())local msg_head = {}local function main_loop() while true do peek_net_msg(1); process(); endendlocal function process() head = msg_read_int() if head == -1 then return 0; end if msg_head[head] then msg_head[head](); end release_net_msg();endlocal function init_msg_head() msg_head[100001] = process_100001endlocal function process_100001() endinit_msg_head()main_loop()文件 Player.lua
--local createPlayermodule(..., package.seeall)local Player = { name="arch", career=0, level=1 }local PlayerMt = {__index = Player}function createPlayer(name,career) return setmetatable( { name = name, career = career, level = 1 } ,PlayerMt)endfunction Player:getlevel() return self.levelendfunction Player:levelup() self.level = self.level + 1endfunction Player:getname() return self.nameendfunction Player:getcareer() return self.careerendfunction Player:setcareer(nc) self.career = ncend
转载地址:http://hiozx.baihongyu.com/