Forums

Creating a library

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

Creating a library

Postby Sovietaced » Fri Nov 29, 2013 3:09 am

What are best practices/conventions for coding a Cobra library?

I'm getting compilation errors for having no main method. Is there an option to suppress compilation errors in this event? Should I simply insert an empty class with an empty main method to supress the warning?

I have cloned down projects listed in the wiki and none of them compile unfortunately, the code must run on an older version of Cobra. If they don't compile I'm not sure if I should follow their conventions.

I'm specifically getting errors that other classes cannot be found although they exist in the same namespace. I tried using import but I'm getting this error : " error: Expecting use, assembly, namespace, class, interface or enum, but got "import"." What is odd is that the keyword is listed in the source here : http://cobra-language.com/trac/cobra/br ... pecs.cobra

Thanks
Sovietaced
 
Posts: 9

Re: Creating a library

Postby Charles » Fri Nov 29, 2013 10:47 am

Use -target:lib to create a library:
Code: Select all
cobra -target:lib foo.cobra
-->
foo.dll & foo.dll.mdb or foo.pdb


For namespaces, use them in each file:
# foo.cobra

namespace A.B

class Foo

pass


# bar.cobra

namespace A.B

class Bar

pass


Code: Select all
cobra -target:lib foo.cobra bar.cobra


We'll have to take a look at the external projects and get them updated.
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Creating a library

Postby Sovietaced » Fri Nov 29, 2013 4:06 pm

So popped the compiled lib files into a lib directory and then created a test file as follows. I'm getting the following compilation error : test.cobra(1): error: Cannot find namespace "A.B".

use A.B

class Test
def main
f = Foo()


Also, how do you use classes from other modules? Both foo and bar are declared to be inside the same namespace but I can't access each other.

# bar.cobra

namespace A.B

class Bar

def main
t = Foo()


Compilation returns : bar.cobra(8): error: Cannot find "Foo".
Sovietaced
 
Posts: 9

Re: Creating a library

Postby Sovietaced » Fri Nov 29, 2013 5:59 pm

Disregard. Compiling all the files at once solves any inter-module dependencies.
Sovietaced
 
Posts: 9

Re: Creating a library

Postby Charles » Fri Nov 29, 2013 7:50 pm

Glad you got through it. The "import" keyword was reserved simply in case we wanted to use it in the future. It's not currently used for anything.

"namespace Foo" declares a namespace

"use Foo" uses another namespace
Charles
 
Posts: 2510
Location: Los Angeles, CA

Re: Creating a library

Postby Sovietaced » Fri Nov 29, 2013 10:17 pm

Charles wrote:Glad you got through it. The "import" keyword was reserved simply in case we wanted to use it in the future. It's not currently used for anything.

"namespace Foo" declares a namespace

"use Foo" uses another namespace


The only compiled language I've used extensively is Java and I guess I just took it for granted all the magic that Eclipse does :)
Sovietaced
 
Posts: 9

Re: Creating a library

Postby hopscc » Tue Dec 03, 2013 2:34 am

There is a new wiki page for creating and using libraries in cobra
(off LibraryTopics --> Libraries in Cobra )

If you get a chance pls have a look and see if it would have clarified your understanding of how to use and make libraries in cobra..
hopscc
 
Posts: 631
Location: New Plymouth, Taranaki, New Zealand

Re: Creating a library

Postby Sovietaced » Thu Dec 05, 2013 7:25 pm

hopscc wrote:There is a new wiki page for creating and using libraries in cobra
(off LibraryTopics --> Libraries in Cobra )

If you get a chance pls have a look and see if it would have clarified your understanding of how to use and make libraries in cobra..


That is perfect man! Really awesome thanks, clears everything up.
Sovietaced
 
Posts: 9

Re: Creating a library

Postby hopscc » Fri Dec 06, 2013 6:07 am

And thus we advance. :)
hopscc
 
Posts: 631
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron