Learning Lua Part 17 - Passing Arguments to Parameters

preview_player
Показать описание
Learn to program in Lua. Lua is a popular scripting language that is widely used by many apps and game engines including Roblox, Manticore, Solar 2D (formerly Corona SDK), Defold, Cocos2Dx, neovim, minetest, Amazon Lumberyard, WoW, Adobe Lightroom, and many other great tools.


In Part 17, we examine how to pass arguments to parameters in functions and how to return information to the calling command.
Unlock the power of Lua programming with my latest book, "Learning Lua." Whether you're a beginner or an experienced coder, this comprehensive guide will take you on a journey to mastering Lua. Get your copy now:

Рекомендации по теме
Комментарии
Автор

Learnt a lot from this tutorial, thanks!

mk
Автор

1:20 what does return do outside of a function at the bottom next to sample? I've seen this at the beginning of files in front of a table as well. How can it return something that hasn't changed? And return it to where.

yuridanylko
Автор

Great and simple to understand as always, thanks a lot!
I have one question though: around 5:54, when we assign tablePass(myTable) to the variable local myNewTable, does that mean that the function tablePass (with the parameter myTable) gets automatically called when running the program (since calling showTable(myTable) then prints the sorted table)?
Thanks in advance.

aaaa_
Автор

Thank you for your videos!
I have a question: Could it be a smart programming convention for my (not yet existing Lua programs :D) to create functions, which *should* modify the passed table, without a return value (a void function in c++ terms) in that it makes it clear that the argument's reference is modified ("passing by non const reference") and, on the other hand, create a function with a return value (letting it copy the passed argument inside the function and modifying and returning the copy) to make it clear that the argument will not be changed ("pass by value")?

LukCsa
Автор

Could you elaborate on how sample can be declared as local? Wouldn't it go out of scope since it is in a different file?

bobu