언어/lua

8. 함수

조규현15 2015. 12. 1. 09:03
반응형
  • Optional Function Scope: You can use keyword local to limit the scope the function or ignore the scope section which will make it a global function.

  • Function Name: This is the actual name of the function. The function name and the parameter list together constitute the function signature.

  • Arguments: A argument is like a placeholder. When a function is invoked, you pass a value to the argument. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the arguments of a method. Arguments are optional; that is, a method may contain no argument.

  • Function Body: The method body contains a collection of statements that define what the method does.

  • Return:In Lua, it is possible to return multiple values by follwing the return keyword with the comma separated return values.

--[[ function returning the max between two numbers --]]
function max(num1, num2)

   if (num1 > num2) then
      result = num1;
   else
      result = num2;
   end

   return result; 
end

print("The maximum of the two numbers is",max(10,4))


반응형

'언어 > lua' 카테고리의 다른 글

10. 매트릭스  (0) 2015.12.01
9. 클래스  (0) 2015.12.01
6. 중간 정리  (0) 2015.12.01
5. 연산자  (0) 2015.12.01
4. 자료형  (0) 2015.12.01