在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
lua语言作为一门轻量级脚本语言,能够非常好的被嵌入到应用程序,因此,在移动游戏开发中举足轻重 然后C/C++开发人员转lua并非非常习惯,我也是。。所以,一起努力学习lua吧 lua没有类的概念,有table的概念 <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);">function create(name,id) </span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> local obj={name = name ,id = id}</span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> function obj:setName(name)</span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> self.name=name</span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> end</span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> function obj:setID(id)</span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> self.id=id</span> <span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);"> end</span> end lua能够用继承的概念 --基类 function createRobot(name,id) local obj={name =name, id= id} function obj:setName(name) self.name=name end function obj:getName() return self.name end function obj:setID(id) self.id=id end function obj:getID() return self.id end return obj end --派生类 function createFootballRobot(name,id,position) local obj=createRobot(name,id) obj.position="right" return obj end
|
请发表评论