mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
chains can implicitly return
This commit is contained in:
parent
9c0fced067
commit
72eca8071c
@ -485,17 +485,18 @@ local compiler_index = {
|
||||
stm = function(self, node, return_value)
|
||||
local value = self:value(node, return_value)
|
||||
|
||||
if must_return[ntype(node)] then
|
||||
if return_value then
|
||||
local return_to = "return"
|
||||
if type(return_value) == "string" then
|
||||
return_to = return_value.." ="
|
||||
end
|
||||
local is_value = must_return[ntype(node)]
|
||||
local ret_chain = ntype(node) == "chain" and node[2] ~= "return"
|
||||
|
||||
return return_to.." "..value
|
||||
else
|
||||
return self:value({"assign", {"_"}, {value}}, false)
|
||||
if return_value and (is_value or ret_chain) then
|
||||
local return_to = "return"
|
||||
if type(return_value) == "string" then
|
||||
return_to = return_value.." ="
|
||||
end
|
||||
|
||||
return return_to.." "..value
|
||||
elseif is_value then
|
||||
return self:value({"assign", {"_"}, {value}}, false)
|
||||
end
|
||||
|
||||
return value
|
||||
|
@ -54,7 +54,7 @@ for z in items do
|
||||
end
|
||||
end
|
||||
require("util")
|
||||
local dump = function(x) print(util.dump(x)) end
|
||||
local dump = function(x) return print(util.dump(x)) end
|
||||
local range = function(count)
|
||||
local i = 0
|
||||
return(coroutine.wrap(function()
|
||||
|
@ -1,13 +1,13 @@
|
||||
local x = function() print(what) end
|
||||
local x = function() return print(what) end
|
||||
local _ = function() end
|
||||
_ = function()
|
||||
return function() return function() end end
|
||||
end
|
||||
go(to(the(barn)))
|
||||
open(function() the(function() return door end) end)
|
||||
open(function() return the(function() return door end) end)
|
||||
open(function()
|
||||
the(door)
|
||||
local hello = function() my(func) end
|
||||
local hello = function() return my(func) end
|
||||
end)
|
||||
local h = function() return hi end
|
||||
eat(function() end, world)
|
||||
@ -40,21 +40,21 @@ return(5 + function() return 4 + 2 end)
|
||||
return(5 + (function() return 4 end) + 2)
|
||||
print(5 + function()
|
||||
_ = 34
|
||||
good(nads)
|
||||
return good(nads)
|
||||
end)
|
||||
something('else', "ya")
|
||||
something('else')
|
||||
something("else")
|
||||
here(we)("go")[12123]
|
||||
local something = { test = 12323, what = function() print("hello world") end }
|
||||
local something = { test = 12323, what = function() return print("hello world") end }
|
||||
print(something.test)
|
||||
local frick = { hello = "world" }
|
||||
local argon = { num = 100, world = function(self)
|
||||
print(self.num)
|
||||
return({ something = function() print("hi from something") end })
|
||||
return({ something = function() return print("hi from something") end })
|
||||
end, somethin = function(self,str)
|
||||
print("string is", str)
|
||||
return({ world = function(a,b) print("sum", a + b) end })
|
||||
return({ world = function(a,b) return print("sum", a + b) end })
|
||||
end }
|
||||
something.what()
|
||||
argon:world().something()
|
||||
@ -82,7 +82,7 @@ else
|
||||
_ = whack
|
||||
end
|
||||
local arg = { ... }
|
||||
x = function(...) dump({ ... }) end
|
||||
x = function(...) return dump({ ... }) end
|
||||
x = not true
|
||||
local y = not (5 + 5)
|
||||
y = #"hello"
|
||||
|
@ -3,7 +3,7 @@ local backpack = {
|
||||
yeah = 200,
|
||||
they = function()
|
||||
print("hello")
|
||||
yor_feet("small")
|
||||
return yor_feet("small")
|
||||
end,
|
||||
pretty = hair,
|
||||
gold = hmm
|
||||
|
Loading…
Reference in New Issue
Block a user