当前位置:网站首页>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
边栏推荐
猜你喜欢

Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation

Easy to use map visualization
![[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid](/img/0d/a8f4424add7785375741bac4f0b802.png)
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid

78岁华科教授冲击IPO,丰年资本有望斩获数十倍回报

DB engines database ranking in July 2022: Microsoft SQL Server rose sharply, Oracle fell sharply

爬虫初级学习

ISO27001 certification process and 2022 subsidy policy summary

就在今天丨汇丰4位专家齐聚,共讨银行核心系统改造、迁移、重构难题

7 RSA Cryptosystem
![[Huawei HCIA continuous update] SDN and FVC](/img/02/f86b509fdc515f14a4497090f0d070.png)
[Huawei HCIA continuous update] SDN and FVC
随机推荐
2022年DCMM认证全国各地补贴政策汇总
Lua EmmyLua 注解详解
【HCIA持续更新】广域网技术
【华为HCIA持续更新】SDN与FVC
数学分析_笔记_第7章:多元函数的微分学
Heartless sword Chinese translation of Elizabeth Bishop's a skill
华为云ModelArts的使用教程(附详细图解)
我写了一份初学者的学习实践教程!
Open source PostgreSQL extension age for graph database was announced as the top-level project of Apache Software Foundation
[HCIA continuous update] WAN technology
无心剑中译伊丽莎白·毕肖普《一门技艺》
[daily question] 556 Next bigger element III
How to test MDM products
网上开户安全吗?是真的吗?
I2C子系统之适配器的设备接口分析(i2c-dev.c文件分析)
【211】go 处理excel的库的详细文档
爬虫初级学习
要上市的威马,依然给不了百度信心
创业两年,一家小VC的自我反思
Device interface analysis of the adapter of I2C subsystem (I2C dev.c file analysis)