当前位置:网站首页>Lua emmylua annotation details
Lua emmylua annotation details
2022-07-04 18:14:00 【Doule eight gods】
Lua EmmyLua Annotations,
Why
In order to make IDE Coding experience is similar to strong language
Give Way IDE Discover coding errors in advance
BUG It's easier to find
Code reading is more convenient
Suggest
Specify field type
Specify the field access modifier
Specify the method parameter type
Make good use of “:” Inherit “|” or "," Multiple
Support formats
– class —@class MY_TYPE[:PARENT_TYPE] [@comment]
– type —@type MY_TYPE[|OTHER_TYPE] [@comment]
– Alias —@alias NEW_NAME TYPE
– Parameters —@param param_name MY_TYPE[|other_type] [@comment]
– Return value —@return MY_TYPE[|OTHER_TYPE] [@comment]
– Field —@field [public|protected|private] field_name FIELD_TYPE[|OTHER_TYPE] [@comment]
– Generic —@generic T1 [: PARENT_TYPE] [, T2 [: PARENT_TYPE]]
– Uncertain parameters —@vararg TYPE
– Embedded language —@language LANGUAGE_ID
– Array —@type MY_TYPE[]
– Dictionaries —@type table<KEY_TYPE, VALUE_TYPE>
– function —@type fun(param:MY_TYPE):RETURN_TYPE
Complete examples on the official website
—@class Transport @parent class
—@field public name string
local transport = {}
function transport:move() end
—@class Car : Transport @Car extends Transport
local car = {}
function car:move() end
—@class Ship : Transport @Ship extends Transport
local ship = {}
—@param type number @parameter type
—@return Car|Ship @may return Car or Ship
local function create(type)
– ignored
end
local obj = create(1)
—now you can see completion for obj
—@type Car
local obj2
—now you can see completion for obj2
local list = { obj, obj2 }
—@param v Transport
for _, v in ipairs(list) do
—not you can see completion for v
end
Verify the example yourself
—@class TestBase @ Base class
—@field protected key number @ Base class fields
—@class Test : TestBase @ Test class
—@field bool boolean @boolean The type field
—@field numberArray number[] @ Array
—@field numberDictionary table<number,number> @ Dictionaries
—@type Test
local Test = {}
—@type number @number The type field ( Later extended fields IDE Unrecognized comments )
Test.num = 0
— Method 1
function Test:Func1()
– Field test
self.key = 0 -- Can jump to base class
self.bool = false
self.num = 1 --IDE Unrecognized comments
for i, v in ipairs(self.numberArray) do end
for k, v in pairs(self.numberDictionary) do end -- Traversal can recognize k v type
-- Method test
self:Func2(" Zhang San ")
local tempFunc3 = self:Func3(" Li Si ")
local tempFunc4A, tempFunc4B = self:Func4(" Wang Wu ", false)
local tempFunc5 = self:Func5(false)
end
— Method 2 With parameters
—@param name string @ name
function Test:Func2(name)
end
— Method 3 There is a return value
—@return string @ Return type
function Test:Func3(name)
return name
end
— Method 4 multi-parameter Multiple return values
—@param name string @ name
—@param sex boolean @ Gender
—@return string , number @ Return type
function Test:Func4(name, sex)
return name, sex
end
— Method 5 Multiple types of parameters Multiple types of return values
—@param sex string | boolean @ Gender
—@return string | boolean @ Return type
function Test:Func5(sex)
return sex
end
— Method 6 The parameter is method
—@param func fun(key:number):string @ function
function Test:Func6(func)
return func(1)
end
– Use see Annotation to mark a reference
—@see Test#Func1
– The following are not commonly used
– Indefinite Parameter annotation
—@vararg string
—@return string
local function format(…)
local tbl = { … } – inferred as string[]
end
– Generic
– Almost no use C# Use it because of object As a parameter There is consumption of packing and unpacking lua Language naturally does not need
—@class Goods @ Item base class
—@field public price number @ Price
—@class Food : Goods @ food
—@field public cal number @ calories
—@class Phone : Goods @ mobile phone
—@field public battery number @ Electric quantity
—@generic T : Goods
—@param object T
function Test:GetPrice(object)
return object.price
end
– Embedded language
—@language JSON
local jsonText = [[{
“name”:“Emmy”
}]]
return Test
边栏推荐
- ITSS运维能力成熟度分级详解|一文搞清ITSS证书
- “在越南,钱就像躺在街上”
- Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
- 表情包坑惨职场人
- Make a grenade with 3DMAX
- Why are some online concerts always weird?
- 蓝桥:合根植物
- Clever use of curl command
- [HCIA continuous update] network management and operation and maintenance
- 12 - explore the underlying principles of IOS | runtime [isa details, class structure, method cache | t]
猜你喜欢
Superscalar processor design yaoyongbin Chapter 5 instruction set excerpt
The block:usdd has strong growth momentum
使用3DMAX制作一枚手雷
Weima, which is going to be listed, still can't give Baidu confidence
股价大跌、市值缩水,奈雪推出虚拟股票,深陷擦边球争议
CocosCreator事件派发使用
"In Vietnam, money is like lying on the street"
【华为HCIA持续更新】SDN与FVC
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
mysql5.7安装教程图文详解
随机推荐
The controversial line of energy replenishment: will fast charging lead to reunification?
为啥有些线上演唱会总是怪怪的?
【Proteus仿真】基于VSM 串口printf调试输出示例
明星开店,退,退,退
78 year old professor Huake impacts the IPO, and Fengnian capital is expected to reap dozens of times the return
ARTS_ twenty million two hundred and twenty thousand six hundred and twenty-eight
超标量处理器设计 姚永斌 第5章 指令集体系 摘录
“在越南,钱就像躺在街上”
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
Face_recognition人脸识别之考勤统计
【211】go 处理excel的库的详细文档
regular expression
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"
TCP两次挥手,你见过吗?那四次握手呢?
Self reflection of a small VC after two years of entrepreneurship
ARTS_20220628
机器学习概念漂移检测方法(Aporia)
【每日一题】556. 下一个更大元素 III