parkjaeman / tiny-js

Automatically exported from code.google.com/p/tiny-js
0 stars 0 forks source link

Polymorphism/Variable # of arguments #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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