Last active
December 28, 2019 12:20
-
-
Save akrabat/3d84ef00357f0df3a9e5eac23eba2ee9 to your computer and use it in GitHub Desktop.
Useful Lua snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Does "str" start with "start"? | |
]] | |
local function starts_with(str, start) | |
return str:sub(1, #start) == start | |
end | |
--[[ | |
Get the item with a getName() of 'name' from the table 'collection' | |
]] | |
local function getFromCollection(collection, name) | |
for _,item in ipairs(collection) do | |
if item:getName() == name then | |
return item | |
end | |
end | |
return nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment