@ -27,15 +27,14 @@ The ~local~ keyword or suffix is typically relative to module scope. It tells Ca
** Importing modules
The ~import~ function adds the specified file to the environment:
#+BEGIN_SRC lisp
(import "MyFile.cake" "AnotherFile.cake")
(import "MyFile.cake" "AnotherFile.cake")
;; Include MyForwardDeclares.cake's generated header in the current module's generated header
;; You might need to do this if you have non-module-local types/signatures which rely on other types
(import &with-decls "MyForwardDeclares.cake")
;; Include MyForwardDeclares.cake's generated header in the current module's generated header
;; You might need to do this if you have non-module-local types/signatures which rely on other types
(import &with-decls "MyForwardDeclares.cake")
;; Do not include in any generated code. This is essential for comptime-only modules, which won't
;; even generate headers
(import &comptime-only "ComptimeHelpers.cake")
;; Do not build the module, only include its header (its declarations)
(import &decls-only "OnlyHeader.cake")
#+END_SRC
By default, ~&with-defs~ is specified, meaning the generated header will be included in the generated source file only.
@ -399,11 +398,6 @@ Basic projects don't need any build customization at all. Cakelisp uses its modu
** Example: Bootstrap
For example, Cakelisp itself consists of C++ code. [[file:../Bootstrap.cake][Bootstrap.cake]] builds Cakelisp, and serves as a good demonstration of the build system. I'll explain it here.
#+BEGIN_SRC lisp
(skip-build)
#+END_SRC
This indicates the current module should not be built, nor be linked into the final executable. ~Bootstrap.cake~ doesn't contain any runtime code, so we omit it. Modules which contain only compile-time functions like macros should also ~skip-build~.
@ -264,10 +264,10 @@ We need to add the command to a compile-time list so that code can be generated
For this, we need some external help, because we don't know how to save data for later during compile-time. Add this to the top of your ~Hello.cake~:
#+BEGIN_SRC lisp
(import &comptime-only "ComptimeHelpers.cake")
(import "ComptimeHelpers.cake")
#+END_SRC
This ~ComptimeHelpers.cake~ file provides a handy macro, ~get-or-create-comptime-var~. We ~import~ it to tell Cakelisp that we need that file to be loaded into the environment. We include ~&comptime-only~ because we know we won't use any code in it at runtime.
This ~ComptimeHelpers.cake~ file provides a handy macro, ~get-or-create-comptime-var~. We ~import~ it to tell Cakelisp that we need that file to be loaded into the environment.
However, if we try to build now, we get an error:
@ -283,7 +283,7 @@ Cakelisp doesn't know where ~ComptimeHelpers.cake~ is. We need to add its direct
#+BEGIN_SRC lisp
(add-cakelisp-search-directory "runtime")
(import &comptime-only "ComptimeHelpers.cake")
(import "ComptimeHelpers.cake")
#+END_SRC
This allows you to move things around as you like without having to update all the imports. You would otherwise need relative or absolute paths to find files. You only need to add the directory once. The entire Environment and any additional imports will use the same search paths.
@ -547,7 +547,7 @@ And to make sure it works, we will reference ~command-table~ in ~main~. We will
Update our ~import~ to include ~CHelpers.cake~, which has a handy macro for iterating over static arrays: