Skip to content

Instantly share code, notes, and snippets.

@akrabat
Last active December 28, 2019 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akrabat/3d84ef00357f0df3a9e5eac23eba2ee9 to your computer and use it in GitHub Desktop.
Save akrabat/3d84ef00357f0df3a9e5eac23eba2ee9 to your computer and use it in GitHub Desktop.
Useful Lua snippets
--[[
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