Skip to content

Commit

Permalink
update namesapce section of interoperability
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 13, 2023
1 parent 2c0aa6a commit 4b2d61a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/cpp/interoperability/namespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
C++ definitions can sometimes be in a namespace. In this case, it is necessary to add the namespace for code generation to be correct. The `namespace` directive is used to specify the namespaces of the definitions.

**Supported types:**
- Variables
- Functions
- Structures

Expand All @@ -24,4 +25,21 @@ fn main() {
cpp.exit(1)
}
```
For the above function call, the code `foo::bar::exit` will be generated.
For the above function call, the code `foo::bar::exit` will be generated.

## Accessing Static Defines

The `namespace` directive can be a kind of trick that can also be used to achieve static definitions.

For example:
```jule
//jule:namespace std::numeric_limits<jule::Int>
cpp fn max(): int
fn main() {
let int_max = cpp.max()
outln(int_max)
}
```

In the example above, the `max` function actually points to the `jule::Int` (ie Jule's type `int`) instance of `std::numeric_limits`. So calls to the `max` function actually happen as `std::numeric_limits<jule::Int>::max()`.
1 change: 1 addition & 0 deletions src/standard-library/std-jule-ast.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ struct VarDecl {
mutable: bool
constant: bool
statically: bool
directives: []&Directive
doc_comments: &CommentGroup
kind: &TypeDecl // nil for auto-typed
expr: &Expr
Expand Down
1 change: 1 addition & 0 deletions src/standard-library/std-jule-sema.md
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ struct Var {
used: bool
statically: bool
reference: bool
directives: []&Directive
doc: str
kind: &TypeSymbol
value: &Value
Expand Down

0 comments on commit 4b2d61a

Please sign in to comment.