Skip to content

Commit 13f8771

Browse files
committed
add namespace directive
1 parent df4f8e8 commit 13f8771

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export default defineConfig({
252252
{ text: 'Structures', link: '/cpp/interoperability/structures' },
253253
{ text: 'Types', link: '/cpp/interoperability/types' },
254254
{ text: 'Macros', link: '/cpp/interoperability/macros' },
255+
{ text: 'Namespaces', link: '/cpp/interoperability/namespaces' },
255256
{ text: 'Jule Wrappers', link: '/cpp/interoperability/jule-wrappers' },
256257
],
257258
},

src/compiler/directives.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ Here is an example code via `build` directive:
5151
//jule:build unix && !darwin
5252
```
5353

54-
## Directive: `typedef`
55-
In C++-linked structs, if the structure is a `typedef` use this will configure code generation correctly. Otherwise, the struct will be treated as a classical structures.
56-
57-
## Directive: `cdef`
58-
In C++-linked functions, if the function is a `#define`, it configures code generation to be compatible.
59-
6054
## Directive: `derive`
6155
Specify what additions the compiler will make.
6256
Supported by only structures.
@@ -88,3 +82,12 @@ fn main() {
8882
The `build` directive is a top directive. Different way of platform specific programming. It can be used with or instead of file annotation. Unlike file annotation, it is a directive, not a naming convention.
8983

9084
Plese look at the [platform specific programming](/compiler/platform-specific-programming) page for information.
85+
86+
## Directive: `typedef`
87+
In C++-linked structs, if the structure is a `typedef` use this will configure code generation correctly. Otherwise, the struct will be treated as a classical structures.
88+
89+
## Directive: `cdef`
90+
In C++-linked functions, if the function is a `#define`, it configures code generation to be compatible.
91+
92+
## Directive: `namespace`
93+
Adds namesapce selection for supported C++-linked types.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Namespaces
2+
3+
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.
4+
5+
**Supported types:**
6+
- Functions
7+
- Structures
8+
9+
## Using `namespace` Directive
10+
11+
The `namespace` directive is simple to use. It precedes the supported definition and specifies the namespace in which the definition resides.
12+
13+
::: warning
14+
Jule also uses the namespace you type directly in code generation, without checking if it writes the namespaces in the correct format. Adds `::` in addition to the namespace.
15+
:::
16+
17+
For example:
18+
```jule
19+
//jule:namespace foo::bar
20+
cpp fn exit(code: int)
21+
22+
fn main() {
23+
const EXIT_CODE = 1
24+
cpp.exit(1)
25+
}
26+
```
27+
For the above function call, the code `foo::bar::exit` will be generated.

0 commit comments

Comments
 (0)