How to use cs.Out for Out parameters in C# Haxe target?

125 views
Skip to first unread message

Jeffrey Campbell

unread,
Apr 26, 2015, 11:02:18 PM4/26/15
to haxe...@googlegroups.com
Hi there, I'm currently porting my C# code to Haxe and have been mostly successful in my efforts. However, one last thing I am having trouble with is marking up Out parameters used in functions like TryGetValue in many of the C# Generic collections. In the example below using Haxe, it passes Haxe compilation but complains when compiling with the Mono compiler that an Out specifier is required, which is what I had thought it was doing. 

// In C#, looks like this...

KeyValuePair<T,V>? element = null;
if (!dictionary.TryGetValue(key, out element))
{
     
// Do foo
}

// In Haxe?
var element:Out<KeyValuePair<T,V>> = null;
if (!dictionary.TryGetValue(key, element))
{
     // Do foo
}


Is there anyone who can show me the proper way to use this typedef or Out parameters from Haxe? Thank you. 

Jeffrey Campbell

unread,
Apr 27, 2015, 1:22:45 PM4/27/15
to haxe...@googlegroups.com
Also, can anyone show me an example of using any of the Generic collections in C# at cs.System.Collections.Generic from Haxe? Searching google for anything on this subject doesn't result in any meaningful results I can use to learn from to answer my own question. Thank you. 

Jeffrey Campbell

unread,
Apr 29, 2015, 8:34:42 AM4/29/15
to haxe...@googlegroups.com
bump 

Juraj Kirchheim

unread,
Apr 29, 2015, 10:53:53 AM4/29/15
to haxe...@googlegroups.com
I don't know much about C#, but I bet the issue comes from function argument not being defined as `cs.Out`, which from the looks of it is the intended usage and works as demonstrated here: https://github.com/HaxeFoundation/haxe/blob/1db20213c0778348afae8ff59bd10a33dc011249/tests/unit/src/unit/TestCSharp.hx#L476

I assume you are using these externs: https://github.com/treejames/haxe-cs-bin/blob/f84a026a6a87acea43940518bfdda0c9ea6be9ef/cslibs/win32-4.0-client/system/collections/generic/IDictionary.hx#L14

That would fit. In that case, fixing the externs would be the right thing to do.

In the future, please try to give more context. I had to make a github code search to find out what you might be talking about ;)

Best,
Juraj

On Wed, Apr 29, 2015 at 2:34 PM, Jeffrey Campbell <mirra...@gmail.com> wrote:
bump 

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Campbell

unread,
Apr 30, 2015, 10:00:53 AM4/30/15
to haxe...@googlegroups.com
Thanks for taking the time to respond! From what it sounds like you're saying, there needs to be a code change for the external definition for that function call to work period; to be honest, I'm not sure how anyone would have found that out without doing a code search, but I'm glad you provided the link so I'll know where to search for in the future should I find a similar issue. For future reference though and to provide better information/ask better questions, what can I help provide when asking questions such as this that would make it easier to understand? Tweaking open source software is new to me, so I probably don't have the best understanding of how to give that context quite yet, particularly for a multi-compilation target like Haxe where people may not have as much knowledge in the target I'm working with. 

I thought providing an example of the function call in C# and what I had thought it was in Haxe was good enough, but I can definitely see if you're not familiar with C# how that could be confusing. Part of the problem for me was in just trying to find an example of how these collections were called from Haxe/trying to turn up examples searching through google or even in Haxe libraries focused on C# turned up zip. I may have to correct that after I get this to work :)

Thanks again for your help; I'll pull that source repo later tonight and tweak it until I can verify that function call is working as intended. 

Jeff

Jeffrey Campbell

unread,
Apr 30, 2015, 1:11:59 PM4/30/15
to haxe...@googlegroups.com
Actually, let me give a bit more background; I'm not using the externs from the library you linked, I'm using this official Haxe C# library. http://lib.haxe.org/p/hxcs. I'll contact that repo owner and go from there. Thanks!

Jeff

Benjamin Dubois

unread,
Apr 30, 2015, 1:16:54 PM4/30/15
to haxe...@googlegroups.com
This lib has been updated to match haxe 3.2, are you using it ?

Jeffrey Campbell

unread,
Apr 30, 2015, 1:21:13 PM4/30/15
to haxe...@googlegroups.com
I am in fact using 3.2.0 of the hxcs library, yep. 


Cauê Waneck

unread,
Apr 30, 2015, 1:35:46 PM4/30/15
to haxe...@googlegroups.com
Hi Jeffrey,

I'm not sure where you are getting this faulty Dictionary definition. The one in the standard library works out-of-the-box:

```
        var dict = new cs.system.collections.generic.Dictionary_2();
        dict.set_Item("a","b");
        var el = null;
        if (dict.TryGetValue("a",el))
        {
            trace(el);
        }
```

I apologize for the lack of documentation about the naming - we're working to complete the Haxe manual in the C# specific area (thanks to Dan Korostelev). Asking the questions here or at #haxe on freenode should be indeed the best way to deal with these questions you might have

Cheers
Cauê
Reply all
Reply to author
Forward
0 new messages