当前位置:网站首页>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
边栏推荐
- 7 RSA Cryptosystem
- With an estimated value of 90billion, the IPO of super chip is coming
- 比李嘉诚还有钱的币圈大佬,刚在沙特买了楼
- 大厂面试总结大全二
- You should know something about ci/cd
- About the pit of firewall opening 8848 when Nacos is started
- Pytorch深度学习之环境搭建
- 内核中时间相关的知识介绍
- 曾经的“彩电大王”,退市前卖猪肉
- Dynamic programming stock problem comparison
猜你喜欢
华为云ModelArts的使用教程(附详细图解)
CocosCreator事件派发使用
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
78岁华科教授冲击IPO,丰年资本有望斩获数十倍回报
简单易用的地图可视化
Easy to use map visualization
The controversial line of energy replenishment: will fast charging lead to reunification?
上市公司改名,科学还是玄学?
【HCIA持续更新】广域网技术
[HCIA continuous update] WAN technology
随机推荐
【HCIA持续更新】WLAN工作流程概述
You should know something about ci/cd
Detectron2 installation method
RecastNavigation 之 Recast
【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
【系统盘转回U盘】记录系统盘转回U盘的操作
【Hot100】31. Next spread
The block:usdd has strong growth momentum
Stars open stores, return, return, return
[system analyst's road] Chapter 7 double disk system design (structured development method)
如何进行MDM的产品测试
【HCIA持续更新】广域网技术
【210】PHP 定界符的用法
Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
Vscode modification indentation failed, indent four spaces as soon as it is saved
Flask 轻量web框架
要上市的威马,依然给不了百度信心
Summary of subsidy policies across the country for dcmm certification in 2022
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions