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