Created
March 19, 2020 09:19
-
-
Save DarkWiiPlayer/2d5346cc46a461ee9c349c82d0be315d to your computer and use it in GitHub Desktop.
This file contains 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
--[[ 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