Forums

Building and Using a dll

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Building and Using a dll

Postby khjklujn » Thu Feb 14, 2008 7:04 pm

I ran into a bit of difficulty trying to build a dll that could be used by referencing it with the -r: option.

I created a file to be used as a dll called Test1.cobra
namespace Bob
class Julie
pass

class George
pass


Then I created a file to use Julie and George called Test2.cobra
use Bob

class Program
def main is shared
print Julie()
print George()


When built together using the -files: option, everything worked as expected.

The way I got them to build independently was:

    copy Cobra.Lang.dll to the local directory
    cobra -t:lib -ert:no Test1.cobra
    cobra -r:Test1.dll Test2.cobra

Building Test1 without -ert:no resulted in redefinition of CobraImp and Tracer errors when I built Test2.

Building Test1 without -ert:no and Test2 with -ert:no resulted in:

error: COBRA INTERNAL ERROR / ArgumentException / An element with the same key already exists in the dictionary.An element with the same key already exists in the dictionary.An element with the same key already exists in the dictionary.An element with the same key already exists in the dictionary.
khjklujn
 
Posts: 29

Re: Building and Using a dll

Postby Charles » Thu Feb 14, 2008 11:48 pm

I'll have to look into the internal error.

Also, when Cobra embeds the run-time, it needs to put a unique id on the Cobra.Lang namespace to avoid collisions.

Finally, I think that down the road, we'll slap Cobra.Lang.dll in the GAC and -ert will default to "no" with a default -r:Cobra.Lang.

Thanks for the report.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Building and Using a dll

Postby khjklujn » Fri Feb 15, 2008 2:04 pm

Okay, one more issue. Using the same Test1.cobra from the previous example and changing Test2.cobra to:
class Program
def main is shared
print Bob.Julie()
print Bob.George()

results in an intermediate file with syntax errors:
Code: Select all
CobraImp.PrintLine(CobraImp.ToString((Bob.new Julie())));
CobraImp.PrintLine(CobraImp.ToString((Bob.new George())));
khjklujn
 
Posts: 29

Re: Building and Using a dll

Postby Charles » Fri Feb 15, 2008 8:27 pm

Confirmed and will fix in the next release.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Building and Using a dll

Postby Charles » Fri Feb 15, 2008 11:29 pm

Well one workaround is to contain the classes in two namespaces. It's only the "one parent namespace" case that breaks. The Cobra test cases for qualified types had two which is why this bug escaped me. I'm adding the "one" and "three" cases now. Only "one" is broken.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 113 guests

cron