Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Illegal break statement #16

Open
Jennal opened this issue May 5, 2016 · 4 comments
Open

SyntaxError: Illegal break statement #16

Jennal opened this issue May 5, 2016 · 4 comments

Comments

@Jennal
Copy link

Jennal commented May 5, 2016

I try my code here:https://raw.githubusercontent.com/Jennal/LuaUtils/master/src/Oop.lua
Click Compile & Run, get the SyntaxError: Illegal break statement
Can you fix this?

@tdzl2003
Copy link
Owner

tdzl2003 commented May 6, 2016

This is a hard work now, cause currently I use function to make variables in correct block.

You can try #4 at luajs.org, compile can give result, but break will be in a function:

    do 
    {
        l.__call(l._f(function()
        {
            var a$2 = 1;
            b$1 = l.__add(b$1,1);
            if ((l.__eq(b$1,3)))
            {
                break;
            }
        }),[]);
    }while (!(l.__eq(l.__get(_ENV,"a"),1)));

This is why thing happens.

I think it would be a simple way to target to ES2015(use let instead of var), and use babel to transform it into ES5 version.

Or we can just learn the way babel do with let, and rewrite it in luajs.

I wrote lua.js in old days(2 years ago). I learned much in these 2 years. I think maybe I should rewrite it in modern ways(commonJS, webpack, ES6, etc...), but I didn't have time in these days.

@tdzl2003
Copy link
Owner

tdzl2003 commented May 6, 2016

The other reason to rewrite lua.js is we can use Proxy to optimize the way that metatable works. This could make lua.js run 25%-100% faster.

@Jennal
Copy link
Author

Jennal commented May 7, 2016

Thank you for you replay. But I think this is a important issue that must be resolved, or lua.js become useless, because break is in common use.

I have an idea to easily solve this issue, you could try this:

do 
{
    var isbreak = false;
    isbreak = l.__call(l._f(function()
    {
        var a$2 = 1;
        b$1 = l.__add(b$1,1);
        if ((l.__eq(b$1,3)))
        {
            return true;//break
        }
    }),[]);
    if (isbreak) break;
}while (!(l.__eq(l.__get(_ENV,"a"),1)));

Just translate break into return, and check the return value after the block.

@tdzl2003
Copy link
Owner

tdzl2003 commented Jun 3, 2016

This should be fixed in recent commits. I'll update web version later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants