ug4
|
For any questions, contact martin.rupp@gcsc.uni-frankfurt.de.
ugshell has the following build-in command-line options:
-outproc id
— Sets the output-proc to id. Default is 0.-ex scriptname
— Executes the specified script.-noquit
— Does run the interactive shell after specified script.-noterm
— Terminal logging will be disabled.-logtofile filename
— Output will be written to the specified file.Script files are written in LUA, see Scripting Tutorials for an introduction.
You can also use the command line to pass arguments to your scripts:
./ugshell -ex tutorials/tut02_loading_a_domain.lua -grid unit_square/unit_square_quads_2x2.ugx
You can access command line parameters by using the lua function from util.lua:
For that, you have to include the ug_util.lua
file using ug_load_script("ug_util.lua")
.
ug_load_script will search for files in the following directories (in that order)
If there is no commandline argument "-grid"
, then the second argument is returned by util.GetParam
. Otherwise, the argument after "-grid"
in the commandline is returned. Notice that omitted parameters to Lua-functions are treated as nil
, so util.GetParam("-grid")
is the same as util.GetParam("-grid", nil)
. If you want your argument to be casted to a number, use util.GetParamNumber
:
If the argument is not a number, the second argument is returned. To check if an option is in the command line, use util.HasParamOption
:
Examples:
You can abort the execution of ug4 out of Lua scripts by using exit()
. If you want to stop the execution of a script at a specific place, but you want to use the interactive shell thereafter, insert at that place a call like error("break")
(or whatever message sounds reasonable to you) and start the run with the -noquit
. option
When starting ugshell without arguments, you get the following output:
ug:>
and a blinking cursor: This is called the interactive shell. Interactive shell is disabled when you use -ex
without -noquit
and if ug4 is running in parallel.
In the interactive shell you can do everything just like in a .lua file, for example: <scriptname>
(as usual) by executing ug_load_script()
:
ug:> ug_load_script(<scriptname>)
The interactive ugshell has some auto-completion features implemented. When you enter a part of something and hit tab ugshell tries to auto-complete your input. If there is not a unique completion, and you hit tab again, you get a list of possible completions.
"../scr"
-> "../scripts/"
mainProfileNode:cal
-> mainProfileNode:call_tree
math.e
-> math.exp
You can get Information about the current state of Lua by the following methods:
TypeInfo
prints all information available for the data you insert. Note that you have to enclose your type name with "</tt>.
Example: <tt>TypeInfo("Grid")
. TypeInfo
works with TypeInfo
can be abbreviated by using ug:> Grid?and hitting enter. When the name left to the cursor is unambiguous, hitting tab three times also displays information about the object. Functions show their parameters when you enter the function and the first bracket
ug:> GetProfileNode(and hit tab.
ClassUsage
prints the usage of the class, that is:
Example (excerpt):
ug:> ClassUsage("Domain2d") --- Functions returning Domain2d: --- Domain2d* IApproximationSpace2d:domain() --- Functions using Domain2d: --- bool Domain2d:LoadDomain (Domain2d* Domain, string Filename, integer Number Refinements) bool Domain2d:DistributeDomain (Domain2d* ) IRefiner* Domain2d:GlobalDomainRefiner (Domain2d* ) Domain2d:TestDomainInterfaces (Domain2d* ) IApproximationSpace2d:assign_domain ([Domain2d* ]) DirichletBND2d:set_domain ([Domain2d* ]) Instantiations of Class Domain2d: dom (Domain2d)
Listing
list_luaObjects()
: Lists all Objects created by lua or in lua scripts. list_cfunctions()
: Lists all global functions provided by the current registry. list_classes()
: Lists all Classes provided by the current registry. list_scriptFunctions()
: Lists all LUA functions provided by you or loaded scripts. list_internalFunctions()
: Lists all functions (these are also internal registry or lua functions). ls()
lists all of the above. You can also debug your Lua Script using the shell. For this, you can use the script functions
breakpoint()
breakpoint()
breaks the execution of the script at exactly the location it stands. This is the preferred method of setting a breakpoint. breakpoint(source, line)
breakpoint("laplace.lua", 69)
adds a breakpoint at the file "laplace.lua"
(path relative to current script). print_breakpoints
prints those. Note that only lines with code are "catched" by the compiler. When your breakpoint is reached, you are entering the ug4 debug shell:
./../scripts/laplace.lua:69 breakpoint() debug:>
The debug shell is like the normal ugshell (so it has Auto Completion and Runtime Information), but you have some extra commands. Most of them have a similar function as in gdb:
continue, cont
— Continues execution.step
— Continues execution until the next line is reached, steps into subroutines.next
— Continues execution until the next line is reached, does not step into subroutines (that is, we are skipping lines with greater function stack depth).finish
— Finishes subroutines/scripts (continues execution until a line is reached with lower function stack depth).list
— Lists the script surrounding the current statement.backtrace, bt
— Prints the function stack.up, down
— Goes up and down the function stack.quit, exit
— Like in normal shell, exits ug4 directly.print VAL
— Like VAL?
Note that you don't have to configure ug4 with cmake -DDEBUG=ON ..
) to use the debug shell. There is a small performance drawback when using breakpoint(source, line)
because we have to check for every line if it is a break line. This is especially the case if you have lots of small calls in your Lua script. However, there is no performance drawback in breakpoint()
.