Skip to content

Commit

Permalink
add @import examples:
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 24, 2024
1 parent fbf0598 commit e00ff6f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/import/Foo.ck
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// define a public Foo class (picked up by @import)
public class Foo
{
// member variable
int num;

// constructor
fun Foo( int n ) { n => num; }
}

// a non-public class definition (ignored by @import)
class Bar
{
// ...
}

// public operator overloading + for Foo (picked up by @import)
public Foo @operator +( Foo lhs, Foo rhs )
{
// return a new Foo
return new Foo ( lhs.num + rhs.num );
}

// non-public binary operator overload for '=>' (ignored by @import)
fun void @operator =^( Foo lhs, Foo rhs )
{
// for sake of example, just print contents
<<< lhs.num, "=^", rhs.num >>>;
}
8 changes: 8 additions & 0 deletions examples/import/import-test-1.ck
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// import
@import "Foo.ck"

// instantiate class defined in imported file
Foo a(1), b(2);

// use operator overload defined in imported file
<<< (a + b).num >>>;

0 comments on commit e00ff6f

Please sign in to comment.