本文主要介紹@命名注釋(枚舉注釋),下面一起看看@命名注釋(枚舉注釋)相關(guān)資訊。
前言#在線配置emmylua的方法有很多,所以我贏了 這里就不贅述了(所以前提是你已經(jīng)安裝并配置了emmylua)。
本文只是emmylua插件中注釋函數(shù)使用的代碼演示。因?yàn)檫@部分在大部分網(wǎng)上emmylua配置教程中都沒有講解,而emmylua的注釋功能在實(shí)際lua開發(fā)中幾乎是必不可少的,所以我假裝這篇文章。
注釋的目的#當(dāng)我們在編寫c#腳本時,ide的相關(guān)插件可以提示各種方法或成員,并描述:
但是在lua中,即使安裝了emmylua,如果你不 t寫注釋,不會有提示(灰色提示只表示參數(shù)剛剛寫完,你沒有 我根本不知道它是成員變量還是方法):
所以emmylua注釋函數(shù)就是為了解決這個問題:模擬實(shí)現(xiàn)代碼提示。
用法# class #基本格式聲明:-@ class my _ type[echo 1-@ . parent _ type][@ comment]
-@ class person person = { };-@ class gam:人gamer = { };一個類的附加屬性#即使該類沒有持有某個屬性,也可以通過添加注釋的出現(xiàn)在提示中(ps:其實(shí)emmylua s提示實(shí)現(xiàn)unityapi也是基于此)。
基本格式:-@ field[public | protected | private]field _ name field _ type[| other _ type][@ comment]
-@ class person person-@ field public name string name-@ field private m _ a number age person = { name = ,};變量類型#基本格式:-@ type my _ type[| other _ type][@ comment]
標(biāo)簽數(shù)組:-@ typemy _ type []
注釋字典:-@ typetablekey _ type,value _ type。
ps:按照上面官方的用法,評論的描述應(yīng)該放在最后,但是我嘗試了這個。類型不大,可以放在最上面。
-我的id-@ type number myid = 1;-gamer的一個例子-@ type gamer gamera = gamer : create;-玩家陣列-@ type gamer[]gamers arr = { };-播放器和播放器;;s字典-@ typetablenumber,gamer stable = { };function #表示函數(shù)定義參數(shù)的類型:-@ param param _ name my _ type[| other _ type][@ comment]
批注函數(shù)返回值的類型:-@ return my _ type[| other _ type][@ comment]
標(biāo)簽函數(shù)的不定參數(shù):-@ varargtype
-get lines-@ paramiscn boolean是中文-@ paramid # lines字典id-@ returnstring lines函數(shù)getlines (iscn,id)local str = -做一些事情返回strend -累積和-@ varargnumber累積數(shù)-@返回?cái)?shù)和函數(shù)addnum(...)局部合計(jì)= 0;對于_,v成對{...} do total = total v;最終退貨總額;end type的別名#對于變量類型的注釋,通常可以使用上面提到的- @type(常用的類型有string|number|boolean|table|...或者- @class聲明的用戶自定義類型),但是如果遇到復(fù)雜類型(比如閉包函數(shù)),可以使用alias annotation將一些復(fù)雜且難以輸入的類型注冊為新的別名:
基本格式:-@ aliasn:字符串): void返回函數(shù)(logmsg) if(logl: ..logmsg);: ..logmsg);endended-@ type logprinterlocal lp = genlog printer(1);-@ type logprinterlocal lp _ warning = g:一個正常日志。lp _ warning( 警告日志。 );-警告:一個警告日志。嵌入式語言#用于標(biāo)記某一段代碼格式的文本(json、xml、java等。)這樣才能突出。
基本格式:-@ languagelanguage _ id
-@ language json local jsontext =[[{ 姓名和名稱: 小丑 、;ag: 18 }]-@ language xml local xmltext =[[person name value = 小丑 /age value = 18 //person]]備注#在這個思路下,對目標(biāo)使用alt enter快捷鍵(或者點(diǎn)亮一個小燈泡),這樣更容易自動完成評論:
具體例子#現(xiàn)有的person基類,gamer類繼承自person,兩個類的創(chuàng)建和使用都在main.lua中實(shí)現(xiàn)(貼在本地運(yùn)行即可):
main.lua:
要求( 人與自然);要求( 游戲玩家 );-@ type person local pa = person : create( 小丑 , 18);pae cho 1-@ . comshowinfo;pa: rename( 小丑 );pae cho 1-@ . com show info-@ type gamer local ga = gamer : create( ??怂?,19,零,零);gae cho 1-@ . comshowinfo;gae cho 1-@ . com rename( ??怂?);gae cho 1-@ . comregamerinfo( 一23 , 456 );gae cho 1-@ . comshowinfo;person.lua:
-@ classperson人類型-@ field public name string name-@ field private m _ age number age person = { name = ,m_age = 0,};人。__index =人;-create-@ param name string-@ param age number function person : create(name,age)-@ type person local t = { };s:r:reage(年齡);return t;end-rename-@ param newname string-@ public function person : rename(newname)self。name = newnameend-reage-@ param new age number-@ private function person : reage(new age)self . m _ age = new age;end-showinfo-@ public function person : showinfoprint( name = ..自我。名字.. ,年齡= ..self . m _ age);endgamer.lua:
要求( 人與自然)-@ class gam:個人玩家-@ field private sw string sw cod:create(姓名,年齡,sw,steamid)-@ type gamer local t = { };t = p:cr:regamerinfo(sw,steamid);return t;end-rega merinfo-@ param sw string-@ param steamid string-@ public function gamer: rega merinfo(sw,steamid) self。sw = sw或 0 自我。steamid = steamid或 0 end-showinfo-@ public function gamer:showinfoprint( nam——模擬類,繼承,多態(tài)性-馬三 的代碼實(shí)踐。
參考文章# emmyloua標(biāo)簽:
注釋功能
了解更多@命名注釋(枚舉注釋)相關(guān)內(nèi)容請關(guān)注本站點(diǎn)。