1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "nel/misc/types_nl.h"
21 #include "nel/misc/debug.h"
22 #include "nel/misc/log.h"
23 #include "nel/misc/displayer.h"
25 // include the command system
26 #include "nel/misc/command.h"
27 #include "nel/misc/variable.h"
34 // with this macro, you can execute a specific command in real time.
35 // this is an example of a command, the first param is the name of the command
36 // (note that it is *not* a string). the second param is the help string that will
37 // be displayed when the user calls the help command. the third param is the
38 // usage of the command. it can the an empty string when the command doesn't
39 // need any parameters.
40 // when the program is launched, you can type the name of the command with
41 // parameters if needed and it will be executed.
42 NLMISC_COMMAND(square
,"display the square of the parameter","<value>")
44 // this code will be executed when the user will call this command.
45 // you have access to some variables:
46 // - args is a vector of strings. they are the user parameters, you have to
47 // check if enough parameters are present and if they are in a good
49 // - log is a CLog object that is used to display the result of the command,
50 // if any. see the log example to know how to use CLog.
52 // this function must return true if the command successfully executed
53 // or false is something wrong happens. for example, if there are not enough
54 // parameters, return false.
56 // check args, if there is not the right number of parameters, return bad status.
57 if (args
.size() != 1) return false;
60 NLMISC::fromString(args
[0], val
);
62 // display the result.
63 log
.displayNL("The square of %d is %d", val
, val
*val
);
88 // Create commands on all variables
91 // with this macro, you can get or set the variable in real time.
92 // this is the easiest way to set or get a variable in real time. you have a direct
93 // access to the variable so you can use this macro.
94 // first param is the type of the variable. second one is the variable name,
95 // and the third one is an help string that describes what the variable does.
96 // when the program is executed, you can type the variable name with no parameter
97 // to see the value of the variable or type the variable name with one parameter
98 // (the value you want to set) to change the variable contents.
99 NLMISC_VARIABLE(bool, MyVar1
, "a dummy variable");
100 NLMISC_VARIABLE(uint8
, MyVar2
, "a dummy variable");
101 NLMISC_VARIABLE(sint8
, MyVar3
, "a dummy variable");
102 NLMISC_VARIABLE(uint16
, MyVar4
, "a dummy variable");
103 NLMISC_VARIABLE(sint16
, MyVar5
, "a dummy variable");
104 NLMISC_VARIABLE(uint32
, MyVar6
, "a dummy variable");
105 NLMISC_VARIABLE(sint32
, MyVar7
, "a dummy variable");
106 NLMISC_VARIABLE(uint64
, MyVar8
, "a dummy variable");
107 NLMISC_VARIABLE(sint64
, MyVar9
, "a dummy variable");
108 NLMISC_VARIABLE(std::string
, MyVar10
, "a dummy variable");
109 NLMISC_VARIABLE(ucchar
, MyVar13
, "a dummy variable");
110 NLMISC_VARIABLE(float, MyVar14
, "a dummy variable");
111 NLMISC_VARIABLE(double, MyVar15
, "a dummy variable");
122 int get() { return _PrivateVar
; }
123 void set(int val
) { _PrivateVar
= val
; }
128 // with this macro, you can get or set the variable in real time.
129 // this is an example of dynamic variable. the goal of this macro is to provide an
130 // easy way to get or set a variable when you don't have a direct access on this variable.
131 // first param is the type of the variable. second one is the name of the variable.
132 // the third one is the help string about this variable (what this variable does).
133 // when the program is executed, you can type the variable name with no parameter
134 // to see the value of the variable or type the variable name with one parameter
135 // (the value you want to set) to change the variable contents.
136 NLMISC_DYNVARIABLE(int,PrivVar
,"dummy variable")
138 // this code will be executed to get or set the variable.
139 // you have to provide a way to do that.
140 // the 'get' boolean says if you have to get or set the variable.
141 // the 'pointer' is a pointer on the variable you have to read or write.
142 // if 'get' is true, you have to set '*pointer' with the value of your variable.
143 // if 'get' is false, you have to set your variable with the value of *pointer
155 // look at the log sample
157 // look at the log sample
158 NLMISC::CStdDisplayer mysd
;
160 int main (int argc
, char **argv
)
162 // look at the debug sample
163 NLMISC::createDebug();
165 // look at the log sample
166 mylog
.addDisplayer(&mysd
);
168 printf("Type a command, 'help' or 'quit'\n");
177 std::string commandLine
;
178 std::getline(std::cin
, commandLine
, '\n');
180 if (commandLine
== "quit")
183 // execute the command line. it will try to find the command or the
184 // variable and call the associated code
185 NLMISC::ICommand::execute(commandLine
, mylog
);