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

Polymorphism/Variable # of arguments #12

Open
GoogleCodeExporter opened this issue Mar 24, 2015 · 3 comments
Open

Polymorphism/Variable # of arguments #12

GoogleCodeExporter opened this issue Mar 24, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

Is there a way to do this in tiny-js?  The way javascript usually handles 
polymorphism is with variable argument counts.  The following seems to fail in 
tiny-js.

function test(a,b)
{
    alert(a);
}

test("hello there!");

alert() is my own function, and it works in browser's javascript.

I'm guessing it wouldn't be hard to implement in this function by padding 
non-existent arguments with nulls:

CScriptVarLink *CTinyJS::functionCall(bool &execute, CScriptVarLink *function, 
CScriptVar *parent) {
  if (execute) {

Am I wrong?  I have slightly out of date code.  If it was added recently I 
would have missed it.  I can hack in an implementation if it's something that 
is desired.

Thanks.

Original issue reported on code.google.com by reirkjs...@gmail.com on 16 Feb 2012 at 5:55

@GoogleCodeExporter
Copy link
Author

Hi,

Are you using the 42-tinyjs branch, or the normal one?

42-tinyjs may actually have this solved, so it might be worth checking out...

Otherwise you're right, it's not a big deal to add it.

In the function you found, where it says:

    while (v) {
        CScriptVarLink *value = base(execute);

you could probably do:

    while (v) {
        CScriptVarLink *value;
        if (l->tk!=')')
          value = base(execute);
        else
          value = new CScriptVarLink(new CScriptVar(TINYJS_BLANK_DATA,SCRIPTVAR_UNDEFINED));

I'm assuming that padding with undefined instead of null is right - that's what 
I thought happened but I may be wrong...

If that works and doesn't break stuff, let me know and I'll add it in...

Original comment by gordon.f...@googlemail.com on 16 Feb 2012 at 6:46

@GoogleCodeExporter
Copy link
Author

It works in 42-tinyjs.  Thanks.

Is 42 the main development branch or are they distinct products?  It may be 
easier for me to stick with the code I have, but if that branch is going to 
disappear I'd rather switch now.

Thanks.


Original comment by reirkjs...@gmail.com on 16 Feb 2012 at 11:46

@GoogleCodeExporter
Copy link
Author

42-tinyjs is Armin's branch, and trunk is the original. 

I use TinyJS in my products and integrate quite deeply with it. At first, 
Armin's changes added a bunch of features that I didn't need, and meant that I 
was having to change my software each time I updated to compile with it. As 
stability was really my goal, I kept trunk on its own and merely made small 
changes to fix problems.

However now, 42-tinyjs is faster and supports a much wider subset of 
JavaScript. If that branch goes anywhere, it'll probably end up as trunk :)

hope that helps :)

Original comment by gordon.f...@googlemail.com on 17 Feb 2012 at 9:08

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

No branches or pull requests

1 participant