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

Class declaration do not check for duplicates #24

Closed
mingodad opened this issue Mar 26, 2016 · 9 comments
Closed

Class declaration do not check for duplicates #24

mingodad opened this issue Mar 26, 2016 · 9 comments

Comments

@mingodad
Copy link
Contributor

Hello !
Squirrel do not check for duplicates in class declarations see example bellow that compiles without errors:

class K
{
    v1 = 0;
    v1 = 0;
    v2 = 0;

    function f1(){}
    function f1(){}
}
@mingodad
Copy link
Contributor Author

SquiLu has fixed this and expanded the subset of C/C++ accepted syntax see this commit:
mingodad/squilu@c644413

@albertodemichelis
Copy link
Owner

because classes "newmember" can be trapped by _newmember, this is a desirable sideffect. I use it in our engine for implementing remote procedure call.

@mingodad
Copy link
Contributor Author

Good point but checking it at compile time do not break what you describe at runtime, and from the syntax and logic point of view it's an error to declare more than one member with the same name, what will be the result of call to that member name ?

Cheers !

@mingodad
Copy link
Contributor Author

Can you give your opinion about accepting a bigger subset of C/C++ in SquiLu, what would be the downsides ?
What can be improved ?
Probably SquiLu will end up trying to do something similar with https://github.com/zdevito/terra, using llvm as backend (fat squirrel as you mentioned before).

Would you be interested in join efforts ?

Cheers !

@mingodad
Copy link
Contributor Author

How to justify this example at compile time:

class K
{
  v1=0;
}
local k = K();
print(k.v1);

class K2
{
  v1=1;
  v1=2;
  function v1(){print("K2");}
}
local k2=K2();
print(k2.v1);

@albertodemichelis
Copy link
Owner

Well "terra" seems to be a quite different language than lua. The syntax is similar but looks like quite a big effort, it's like writing a C++ like language that spits out lua native closures.I must admit it is interesting but to make it into something useful you need debuggers and ide support. That would be my biggest concern, looks like a huge effort.
About member shadowing; it is a choice, I use this semantic if few places in my projects, it has never been a problem. I think even C++ allows shadowing of members in child classes, it is nothing new.

@mingodad
Copy link
Contributor Author

Yes C++ allow shadow of members on child classes but not in the class itself.
Also squirrel allow shadow silently of globals:

gvar <- "global var";
local gvar = "local var";
print("\n");
print(gvar);
local gvar2 = "local var2";
gvar2 <- "global var2";
print("\n");
print(gvar2);

Cheers !

@mingodad
Copy link
Contributor Author

Fixing this in SquiLu I found a piece of code I have with a big class where I had one member function defined twice (an error).
Cheers !

@mingodad
Copy link
Contributor Author

I do not think that it's a good idea leave this issue as it is !
This will give headaches for squirrel users, debugging their code !
Cheers !

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