From 13f877171aae2ff42c211f3b6495f4cd8f77ebaa Mon Sep 17 00:00:00 2001 From: mertcandav Date: Sun, 13 Aug 2023 19:32:53 +0300 Subject: [PATCH] add namespace directive --- .vitepress/config.ts | 1 + src/compiler/directives.md | 15 ++++++++------ src/cpp/interoperability/namespaces.md | 27 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 src/cpp/interoperability/namespaces.md diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 2f27577..57409c0 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -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' }, ], }, diff --git a/src/compiler/directives.md b/src/compiler/directives.md index 0eb96a7..4636593 100644 --- a/src/compiler/directives.md +++ b/src/compiler/directives.md @@ -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. @@ -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. diff --git a/src/cpp/interoperability/namespaces.md b/src/cpp/interoperability/namespaces.md new file mode 100644 index 0000000..edda6ab --- /dev/null +++ b/src/cpp/interoperability/namespaces.md @@ -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. \ No newline at end of file