Closed XeroOl closed 4 years ago
You need to create them as a list of expressions:
terra bar(a: int8, b: int8, c:int8, d:int8): int8
return d
end
local function escape_two()
local rets = terralib.newlist()
rets:insert(`12)
rets:insert(`13)
return rets
end
terra foo(): int8
return bar(3,4,[escape_two()])
end
Or you can just do an inline table like bar(3, 4, [{luaexpr1, luaexpr2}]
Thanks for the help! I was just misunderstanding the docs
Contrary to what the API says, it's not possible to escape multiple expressions in one escape. This is important because it means that there's no way to make vararg escapes.
According to the terra api, it should be possible to have an escape with multiple values. The API provides this as an example, where "[luaexpr] is a multiple-expression escape since it occurs as the last expression in a list of expressions."
Obviously, this example is missing some context (ie a definition of
bar
) before it can compile. Here's what I came up with:I've split the lua expression into two to form a multiple-expression escape. I expected this to compile, with the escape essentially desugaring to
bar(3, 4, 5, 6)
, but instead, there is a compiler error:Since the API reference claims that this behavior is possible, either the API reference or the implementation is wrong.
PS: If you have a lua expression that expands to multiple values, ie
bar(3, 4, [luaexpr()])
, it truncates the function's result down to one value.