Functions को Define और Call करना
एक function code का एक named block है जिसे आप जब ज़रूरत हो चला सकते हैं।
In this page:
Functions Define और Call करना
function name(params) ... end से एक function define करें और parentheses से इसे call करें। Functions values हैं, इसलिए definition एक variable को assign करने का shorthand है। local function prefer करें ताकि function global न हो। अगर एक call में एक single string या table literal argument हो parentheses omit किए जा सकते हैं।
Note:
बिना return statement वाला एक function बिल्कुल कोई values return नहीं करता।
उदाहरण: Defining and calling functions
local function greet(name)
return "Hello, " .. name
end
print(greet("Lua"))
print(type(greet))
local function noReturn() end
print(noReturn())
print(#"abc", type{})
-- Output:
-- Hello, Lua
-- function
--
-- 3 table
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- call करते वक्त parentheses भूल जाना और function खुद पाना
- accidentally globally functions define करना
- function के close पर end miss करना
चैप्टर सारांश
- function name(...) end इस्तेमाल करें
- local function prefer करें
- parentheses से call करें
- कोई return मतलब कोई value नहीं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: