Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Created March 19, 2020 09:19
Show Gist options
  • Save DarkWiiPlayer/2d5346cc46a461ee9c349c82d0be315d to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/2d5346cc46a461ee9c349c82d0be315d to your computer and use it in GitHub Desktop.
--[[ Suggestion:
Add syntax sugar for `foo:bar` to be equivalent to `foo.bar, foo`
--]]
local stack = {
1, 2, 3, 4;
pop = function(self) return table.remove(self) end;
push = function(self, val) return table.insert(self, val) end;
}
local function safe_call(fn, ...)
-- todo: implement safety
return fn(...)
end
local top = safe_call(stack.push, stack, 5)
--[[ Could instead be:
local top = safe_call(stack:push, 5)
--]]
for value in stack.pop, stack do
print(value)
end
--[[ Could instead be:
for value in stack:pop do
print(value)
end
--]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment