Problem with finding almost no documentation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with finding almost no documentation

Martin Richtsfeld
Dear Developers,

I'm pretty new to haxe and try to extend an already existing system. As
it is really hard to find any documentation with simple examples I would
like to ask you for some help.

My goal is to verify any input value. My values can be accessed with
[1], but I have to check first if it is an array.

In as3 I would write something like this:

public function (input:*, index:int):* {
  if (input is Array)
  {
    return input;
  } else {
    if (index == 1)
      return [input];
    else
      return null;
  }
}

In hxformat.abc I would write something like this:

I already have my input on the stack...

aCtx.AddOpcodes([
  OSwap, // to change the position of value and index
  OGetLex(aCtx.Type("Array"), // put an array on the stack to compare
  OOp(Operation.OpIn) // compare the two value, should return boolean ??
]);

aCtx.Purge();
                       
var tJumpFunc:* = ctx.mContext.jump(Jumpstyle.JFalse)

// jump here if we don't have an array
aCtx.AddOpcodes([
  OArray(MyValue) // create an array with the value
]);
               
aCtx.Purge();

var tJumpEndFunc:* = aCtx.mContext.jump(Jumpstyle.JTrue)
                               
tJumpFunc();
// there is an array on the stack and I use it
aCtx.AddOpcodes([
  OGetProp(aCtx.mContext.arrayprop)
]);


This does not work, so thanks in advance for any help. I would also like
to post this example on wiki if it is working so we can collect some
examples.

Regards,
Martin

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem with finding almost no documentation

Ian Martins
Martin Richtsfeld wrote:

> Dear Developers,
>
> I'm pretty new to haxe and try to extend an already existing system. As
> it is really hard to find any documentation with simple examples I would
> like to ask you for some help.
>
> My goal is to verify any input value. My values can be accessed with
> [1], but I have to check first if it is an array.
>
> In as3 I would write something like this:
>
> public function (input:*, index:int):* {
>   if (input is Array)
>   {
>     return input;
>   } else {
>     if (index == 1)
>       return [input];
>     else
>       return null;
>   }
> }
>  
can you just do this:

    public function foo(input:Dynamic, index:Int):Dynamic
    {
      if (Std.is(input, Array))
    {
    return input;
    }  else {
    if( index==1 )
      return [input];
    else
      return null;
      }
    }



--
haXe - an open source web programming language
http://haxe.org