Wiki

Changes between Initial Version and Version 1 of UseDirective

Show
Ignore:
Timestamp:
10/13/08 06:22:51 (16 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseDirective

    v1 v1  
     1= Use Directive = 
     2 
     3{{{ 
     4use <namespace> 
     5use <namespace> from <library-name> 
     6}}} 
     7 
     8Specify a namespace contents to make available to this module 
     9 
     10When using the first form if the compiler cannot immediately locate the namespace,[[BR]] 
     11i.e if its not in the default loaded libraries,[[BR]] 
     12it will look for a (platform dependent) library-name of the same form as  
     13the namespace. 
     14 
     15 
     16If the filename of the library differs from the namespace, you can specify  
     17it with the second form.[[BR]] 
     18  
     19<library-name> can be a simple identifier, qualified identifier (Foo.Bar)  
     20or a string literal. 
     21 
     22{{{ 
     23use Foo.Bar from SomeLib 
     24}}} 
     25You can put single or double quotes around the file name if its components  
     26are not legal identifiers [[BR]] 
     27(for example, the filename has a space or punctuation mark in it). 
     28{{{ 
     29use Foo.Bar from "My Lib" 
     30}}} 
     31 
     32 
     33== Platform == 
     34On .Net <library-name> will refer to a .Net Assembly or dll[[BR]] 
     35 
     36No ".dll" extension is expected (or allowed) in any of the above syntax. 
     37   
     38 
     39For .Net the default loaded libraries are 
     40{{{ 
     41mscorlib.dll 
     42System.dll 
     43Cobra.Lang.dll 
     44}}} 
     45and the library name is the  namespace with ".dll" appended  
     46 
     47e.g 
     48{{{ 
     49use Foo.Bar  
     50# On .Net will look for namespace in Foo.Bar.dll if not already available 
     51}}} 
     52== Examples == 
     53 
     54{{{ 
     55use System.Windows.Forms  
     56use System.Drawing 
     57 
     58class MyForm 
     59        inherits Form 
     60 
     61        def init 
     62                .text = 'Click Me' 
     63                listen .click, ref .handleClick 
     64 
     65        def handleClick(sender as Object, args as EventArgs) 
     66                MessageBox.show('You clicked me!', 'Click') 
     67 
     68class Program 
     69 
     70        def main is shared 
     71                Application.run(MyForm()) 
     72 
     73}}} 
     74 
     75 
     76 
     77== Notes == 
     78 
     79In most cases this syntax means you dont need to specify the commandline 
     80-reference switch  
     81 
     82 
     83With  !MyProg.cobra containing 
     84 
     85{{{ 
     86... 
     87    use Foo.Bar 
     88... 
     89}}} 
     90Instead of compilation by 
     91{{{ 
     92cobra -reference:Foo.Bar MyProg.cobra 
     93}}} 
     94 
     95you can just say: 
     96 
     97 
     98{{{ 
     99cobra MyProg.cobra 
     100}}}