工程结构:
BasePlayer.lua:
1 BasePlayer = {}2 3 BasePlayer.root = "BasePlayer"4 5 function BasePlayer:ShowBaseName()6 print("ShowBaseName : BasePlayer")7 end8 9 return BasePlayer
Player.lua:
1 require "BasePlayer" 2 3 Player = {} 4 5 6 function Player:new() 7 setmetatable(Player,{__index = BasePlayer}) 8 9 self = {}10 setmetatable(self,{__index = Player})11 return self12 end13 14 function Player:ShowPlayerName()15 print("ShowPlayerName : Player")16 end17 18 return Player
Main.lua:
1 require "Player" 2 3 testPlayer = Player:new() 4 5 print(testPlayer.root) 6 testPlayer:ShowBaseName() 7 testPlayer:ShowPlayerName() 8 9 --[[10 运行结果:11 BasePlayer12 ShowBaseName : BasePlayer13 ShowPlayerName : Player14 --]]
码云上的相关工程:https://gitee.com/luguoshuai/LearnLua