bat/tests/syntax-tests/highlighted/Lua/test.lua
2020-10-07 07:37:19 +02:00

35 lines
4.8 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--- Finds factorial of a number.
-- @param value Number to find factorial.
-- @return Factorial of number.
local function factorial(value)
 if value <= 1 then
 return 1
 else
 return value * factorial(value - 1)
 end
end
--- Joins a table of strings into a new string.
-- @param table Table of strings.
-- @param separator Separator character.
-- @return Joined string.
local function join(table, separator)
 local data = ""
 
 for index, value in ipairs(table) do
 data = data .. value .. separator
 end
 
 data = data:sub(1, data:len() - 1)
 
 return data
end
local a = factorial(5)
print(a)
local b = join({ "l", "u", "a" }, ",")
print(b)