Skip to content

Commit

Permalink
add namespace directive
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 13, 2023
1 parent df4f8e8 commit 13f8771
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export default defineConfig({
{ text: 'Structures', link: '/cpp/interoperability/structures' },
{ text: 'Types', link: '/cpp/interoperability/types' },
{ text: 'Macros', link: '/cpp/interoperability/macros' },
{ text: 'Namespaces', link: '/cpp/interoperability/namespaces' },
{ text: 'Jule Wrappers', link: '/cpp/interoperability/jule-wrappers' },
],
},
Expand Down
15 changes: 9 additions & 6 deletions src/compiler/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ Here is an example code via `build` directive:
//jule:build unix && !darwin
```

## Directive: `typedef`
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.

## Directive: `cdef`
In C++-linked functions, if the function is a `#define`, it configures code generation to be compatible.

## Directive: `derive`
Specify what additions the compiler will make.
Supported by only structures.
Expand Down Expand Up @@ -88,3 +82,12 @@ fn main() {
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.

Plese look at the [platform specific programming](/compiler/platform-specific-programming) page for information.

## Directive: `typedef`
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.

## Directive: `cdef`
In C++-linked functions, if the function is a `#define`, it configures code generation to be compatible.

## Directive: `namespace`
Adds namesapce selection for supported C++-linked types.
27 changes: 27 additions & 0 deletions src/cpp/interoperability/namespaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Namespaces

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:**
- Functions
- Structures

## Using `namespace` Directive

The `namespace` directive is simple to use. It precedes the supported definition and specifies the namespace in which the definition resides.

::: warning
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.
:::

For example:
```jule
//jule:namespace foo::bar
cpp fn exit(code: int)
fn main() {
const EXIT_CODE = 1
cpp.exit(1)
}
```
For the above function call, the code `foo::bar::exit` will be generated.

0 comments on commit 13f8771

Please sign in to comment.