PaulBernier / castl

JavaScript to Lua compiler with runtime library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to recursively call named lambda

smagnuso opened this issue · comments

function outer()
{
    return function inner(x) {
         if(x == 10)
              return x;
         return inner.call(x, x+1);
    }(0);
}
console.log("Done: " + outer());

Any thoughts? I tried to implement it, but ended up butchering it :)

$ ../bin/castl.js --cat issue-22.lua

-- Lua code (Lua 5.2):
--------------------------------------------------------------------
local _ENV = require("castl.runtime");
local outer;

outer = (function (this)
do return (function (this, x)
if (_eq(x,10)) then
do return x; end
end

do return inner:call(x,(_addNum2(x,1))); end
end)(_ENV,0); end
end);
console:log((_addStr1("Done: ",outer(_ENV))));

--------------------------------------------------------------------

Looks like the anonymous function doesn't get named. i.e. this is a CASTL bug.