Chi-Tech
devman_01_05_addinglua.h
Go to the documentation of this file.
1
/**\page DevManAddingLua Adding Lua-input to the system
2
3
Lua is the main scripting system used by ChiTech.
4
5
\section devman03_sec0 Adding Lua-input
6
7
## Step 1: Create a source file
8
First create a `.cc` file in the location where you want the lua-input to
9
reside. Example: `CHI_TECH/LuaTest/lua_test.cc`
10
\n\n
11
If the folder where the file resides is not covered by
12
a `CMakeLists.txt` recursion then follow
13
the instructions for \ref DevManAddingCode "adding a code to the system".
14
\n\n
15
<B>Restrictions:</B> The lua-wrapper `.cc` file must be in a folder that
16
is not shared with `.cc` files that contain regular non-lua code. In the example
17
above it means we cannot add the wrapper `.cc` to the general `CHI_TECH` folder.
18
<I>This is because we use a script to convert the doxygen comments to
19
text used in the input manual.</I>
20
21
## Step 2: Define a standard lua template with your input function name
22
In our case the test function will be `LuaTest`. We add `chi` to the front of
23
all input language to distinguish it from other lua functions.
24
\n\n
25
Lua-wrapper functions have no real arguments other than the lua-state and
26
always return an integer representing the number of items returned. For more
27
information on how to handle parameters in lua C-api consult the
28
<a href="https://www.lua.org/pil/24.html">lua-documentation</a>.
29
\n\n
30
<B>General Requirements:</B>
31
- The doxygen comments must start with a forward dash
32
and two asterisks. Like / * * but without spaces which was necessary to show
33
it in this document.
34
- If you use the `param` tag then it must be on its own line. The variable
35
name is followed by an indication of the type of the variable and then
36
by the description of the parameter. <I>This gets used in the documentation
37
script to generate the input reference</I>.
38
- The closing comment must be an asterisk forward slash. Like * / but without
39
the space which was necessary to show it in this document. And must be on its
40
own line.
41
42
\include "../../CHI_TECH/LuaTest/lua_test.cc"
43
44
## Step 3: Add it to the lua-register
45
In the project directory go to the file `CHI_TECH/ChiLua/chi_lua_register.h`
46
and add a `RegisterFunction` call to the register, registering the lua function
47
call to be connected with the lua console. <I>Without out this call the
48
wrapper will not be callable from lua.</I>
49
\n\n
50
If you would like for the function call to be listed under a category then
51
proceed the `RegisterFunction` call with a comment starting exactly with
52
`//module:` which will create a module with text matching the text following
53
this piece.
54
\n
55
\n
56
The module tabulation in the manual and the documentation for the parameters
57
will be processed with a script therefore it is important to comment
58
parameters and return values. Some specific notes in the lua-register file
59
60
- `//module:` provides a categorization of the function on the documenation
61
main page.
62
- `//\ref` will provide a link anchor on the documenation main page.
63
64
\code
65
.
66
.
67
.
68
RegisterFunction(chiLBSGroupsetSetGroupSubsets)
69
RegisterFunction(chiLBSGroupsetSetIterativeMethod)
70
RegisterFunction(chiLBSGroupsetSetResidualTolerance)
71
RegisterFunction(chiLBSGroupsetSetMaxIterations)
72
RegisterFunction(chiLBSGroupsetSetGMRESRestartIntvl)
73
RegisterFunction(chiLBSGroupsetSetWGDSA)
74
RegisterFunction(chiLBSGroupsetSetTGDSA)
75
76
//module:Test scripts
77
RegisterFunction(chiLuaTest)
78
79
80
\endcode
81
82
## Step 4: Include it in the documentation script
83
The module inclusion script is at `CHI_TECH/ChiLua/module_lua_inclusion`. Add
84
the folder where your lua-wrapper resides to this script:
85
86
\code
87
.
88
.
89
.
90
Add_Folder("../../Modules/MonteCarlon/lua")
91
Add_Folder("../../Modules/DiffusionSolver/lua")
92
Add_Folder("../../Modules/LBSSteadyState/lua")
93
94
Add_Folder("../LuaTest")
95
\endcode
96
97
98
## Final step: Test it!!
99
100
Create a script input file and call your function. If it is linked incorrectly
101
the lua scripting system will throw an error like
102
103
`Test.lua:2: attempt to call a nil value (global 'chiLuaTest')`
104
*/
doc
PAGES
ProgrammersManual
devman_01_05_addinglua.h
Generated by
1.9.3