Codex NG
Recurrent Flamer
- Joined
- Jul 24, 2015
- Messages
- 2,994
- Solutions
- 12
- Reaction score
- 1,657
Every time I think of a useful function that can be used in a script I am going to post it here...
These functions will be useful in all distro's as I know and you shall soon or eventually see that the code is the same
Also these functions might help you understand the language a little better, I will update this thread as time goes on.
These functions will be useful in all distro's as I know and you shall soon or eventually see that the code is the same
Also these functions might help you understand the language a little better, I will update this thread as time goes on.
Code:
-- for those times you just want to know if something explicitly contains a value
function isset(value)
return value and true or false
end
Code:
-- for those times when you just want to know if an index exists within a table
function isIndexInTable(table, index)
for i, _ in pairs(table) do
if i == index then
return true
end
end
return false
end
Code:
-- this will allow you to extract numbers from a string while converting them to a number
-- and return either as a table or multiple values
-- please note presently this function does not work with floating point values
function parseInt(words, split)
local t = {}
for number in words:gmatch('%d+') do
t[ #t + 1 ] = tonumber(number)
end
if split then
return unpack(t)
end
return t
end
Last edited: