Forums

Importing Cobra Files

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

Importing Cobra Files

Postby Imagine3163 » Fri Oct 31, 2008 4:20 pm

Right now I am calling

Code: Select all
p = ParseSymbol("foo")

which will create a new ParseSymbol object. When the two cobra files (the one using the statement above and the other "ParseSymbol.cobra") are in the same directory, how can I use some kind of "Include" statement that will tell my current cobra file where to find this "ParseSymbol" object ? Is this possible or do I have to included everything into one .cobra file.
Imagine3163
 
Posts: 5

Re: Importing Cobra Files

Postby Charles » Fri Oct 31, 2008 4:54 pm

Just give both files to the Cobra compiler like so:
Code: Select all
> cobra -c Foo.cobra Bar.cobra
> Foo

# or run in one shot:
> cobra Foo.cobra Bar.cobra
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Importing Cobra Files

Postby mindstormss » Mon Nov 03, 2008 1:34 pm

I know that I just asked this too, but perhaps there should be a way to "include" files, in that if I have a file/library that requires other files, I should not have to include every single file from the main file. Having seperate parts have multiple files and then have every single file included on only one file is kind of annoying.
Eat a live toad the first thing in the morning and nothing worse will happen to you the rest of the day.
mindstormss
 
Posts: 8

Re: Importing Cobra Files

Postby Charles » Mon Nov 03, 2008 5:40 pm

Perhaps you can address this by having a .bat file (or shell script) that contains your compilation line. Cobra itself has a comp.bat that reads:
Code: Select all
Snapshot\cobra.exe -compile -color -debug -ert:yes -timeit %* -files:files-to-compile.text

Which also points out that you can use the -files: option to store your file list off the command line.

Another option is to use something like MSBuild or nant. Although there are no custom Cobra commands for them, I have used nant in the past by just invoking Cobra as an external command.

mindstorms, I'm not clear what you mean by "I should not have to include every single file from the main file". Currently there is no way to include any files from the main .cobra file.

Would it be helpful if Cobra took wild cards like "cobra *.cobra"?

Do you want to post some example command lines and/or source code of what you would like?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Importing Cobra Files

Postby Charles » Mon Nov 03, 2008 6:00 pm

On a related note, I've been planning to add an "import" directive in Cobra that would import the "use" and "namespace" directives from another source file. This comes in handy when building related files like a class hierarchy, or a UI.
# Shape.cobra
use Foo.LibA
use Foo.LibB

namespace Shapes

class Shape
is abstract

def init
pass

# Circle.cobra
import Shape

class Circle
inherits Shape

pass

The Circle class would also be in the "Shapes" namespace and would also have access to the namespaces Foo.LibA and Foo.LibB.

But even with this feature, you would still need to say "cobra -c Shape.cobra Circle.cobra"

I suppose we could try to "chain the imports" so that if you have "import Circle" in a MyProgram.cobra then running MyProgram would import Circle and Shape. But this would seem to break down if the Shape class references another class that it doesn't import...
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 33 guests

cron