Skip to content

Latest commit

 

History

History
150 lines (109 loc) · 1.73 KB

File metadata and controls

150 lines (109 loc) · 1.73 KB

Modules

Module is unique compilation unit to organize code members in project.

module First;

struct Vector
{
    int X;
    int Y;
}

Module name can be dotted:

module First.Second.Third.Fourth;

struct Vector
{
    int X;
    int Y;
}

Importing Modules

Any module can be imported to another by use keyword

// First.cstar
module First;

// Second.cstar
module Second;

use First;

Members Access Modifiers

Members access modifiers can be applied to:

  • top-level and nestedstructs
  • fields
  • functions

Implicit Private Modifier

Access to members without public/internal modifiers is limited to the containing scope.

// First.cstar
module First;

struct Vector
{
    int X;
    int Y;
}

struct Some
{
    Vector Vector;
//  ^^^^^^ ERROR: 'Vector' is not accessible
}

// Second.cstar
module Second;

use First;

struct AnotherSome
{
    Vector Vector;
//  ^^^^^^ ERROR: 'Vector' is not accessible
}

Public Modifier

Access to members with public modifier isn't restricted.

// First.cstar
module First;

public struct Vector
{
    int X;
    int Y;
}

struct Some
{
    Vector Vector; // ok
}

// Second.cstar
module Second;

use First;

struct AnotherSome
{
    Vector Vector; // ok
}

Internal Modifier

Access to members with internal modifier is limited to the current assembly.

// MyProject - First.cstar
module First;

internal struct Vector
{
    int X;
    int Y;
}

struct Some
{
    Vector Vector; // ok
}

// MyProject - Second.cstar
module Second;

use First;

struct AnotherSome
{
    Vector Vector; // ok
}

// MyAnotherProject - Third.cstar
module Third;

use First;

struct AnotherSome
{
    Vector Vector; 
//  ^^^^^^ ERROR: 'Vector' is not accessible
}