Tool script example for lua
-- Define a function named "calculate_sum" that takes two parameters, a and b
function calculate_sum(a, b)
-- Calculate the sum of a and b
local result = a + b
-- Return the result
return result
end
-- Call the calculate_sum function with arguments 10 and 20
local sum = calculate_sum(10, 20)
-- Print the result of the calculation
print("Sum:", sum)
Explanation:
function calculate_sum(a, b)
- This line defines a function namedcalculate_sum
that takes two parameters,a
andb
.local result = a + b
- This line calculates the sum of the parametersa
andb
and assigns it to a local variable namedresult
.return result
- This line returns the value of theresult
variable when the function is called.local sum = calculate_sum(10, 20)
- This line calls thecalculate_sum
function with arguments 10 and 20, and assigns the result to a local variable namedsum
.print("Sum:", sum)
- This line prints the text "Sum:" followed by the value of thesum
variable to the console.