Chi-Tech
devman_01_05_addinglua.h
Go to the documentation of this file.
1/**\page DevManAddingLua Adding Lua-input to the system
2
3Lua is the main scripting system used by ChiTech.
4
5\section devman03_sec0 Adding Lua-input
6
7## Step 1: Create a source file
8First create a `.cc` file in the location where you want the lua-input to
9reside. Example: `CHI_TECH/LuaTest/lua_test.cc`
10\n\n
11If the folder where the file resides is not covered by
12a `CMakeLists.txt` recursion then follow
13the 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
16is not shared with `.cc` files that contain regular non-lua code. In the example
17above 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
22In our case the test function will be `LuaTest`. We add `chi` to the front of
23all input language to distinguish it from other lua functions.
24\n\n
25Lua-wrapper functions have no real arguments other than the lua-state and
26always return an integer representing the number of items returned. For more
27information 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
45In the project directory go to the file `CHI_TECH/ChiLua/chi_lua_register.h`
46and add a `RegisterFunction` call to the register, registering the lua function
47call to be connected with the lua console. <I>Without out this call the
48wrapper will not be callable from lua.</I>
49\n\n
50If you would like for the function call to be listed under a category then
51proceed the `RegisterFunction` call with a comment starting exactly with
52`//module:` which will create a module with text matching the text following
53this piece.
54\n
55\n
56The module tabulation in the manual and the documentation for the parameters
57will be processed with a script therefore it is important to comment
58parameters 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 .
68RegisterFunction(chiLBSGroupsetSetGroupSubsets)
69RegisterFunction(chiLBSGroupsetSetIterativeMethod)
70RegisterFunction(chiLBSGroupsetSetResidualTolerance)
71RegisterFunction(chiLBSGroupsetSetMaxIterations)
72RegisterFunction(chiLBSGroupsetSetGMRESRestartIntvl)
73RegisterFunction(chiLBSGroupsetSetWGDSA)
74RegisterFunction(chiLBSGroupsetSetTGDSA)
75
76//module:Test scripts
77RegisterFunction(chiLuaTest)
78
79
80\endcode
81
82## Step 4: Include it in the documentation script
83The module inclusion script is at `CHI_TECH/ChiLua/module_lua_inclusion`. Add
84the folder where your lua-wrapper resides to this script:
85
86\code
87 .
88 .
89 .
90Add_Folder("../../Modules/MonteCarlon/lua")
91Add_Folder("../../Modules/DiffusionSolver/lua")
92Add_Folder("../../Modules/LBSSteadyState/lua")
93
94Add_Folder("../LuaTest")
95\endcode
96
97
98## Final step: Test it!!
99
100Create a script input file and call your function. If it is linked incorrectly
101the lua scripting system will throw an error like
102
103`Test.lua:2: attempt to call a nil value (global 'chiLuaTest')`
104 */