HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to LuaVariablesNumbers & MathStringsTablesConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Table
🔁 Condition & Loop
🧩 Function
functionMultiple return
Lua›REFERENCE›Function
🧩

Function

Function definition.

CommandDescription
functionDefines a function.
Multiple returnReturns multiple values.

function

Try it yourself →

Defines a function.

Syntax

function name(p) ... return ... end

Description

Defined with function and closed with end. Returns values with return (can return multiple as well).

Example

function square(x)
  return x * x
end
print(square(5))

Expected output

25

When to use?

Preventing code repetition.

Multiple return

Try it yourself →

Returns multiple values.

Syntax

return a, b

Description

Lua functions can return multiple values; received with commas.

Example

function bolKalan(a, b)
  return a // b, a % b
end
local b, k = bolKalan(17, 5)
print(b, k)

Expected output

3	2

When to use?

Dual results like quotient + remainder.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code