| 242 | } |
| 243 | |
| 244 | void AddFunction(asIScriptEngine *engine, string &arg) |
| 245 | { |
| 246 | asIScriptModule *mod = engine->GetModule("console", asGM_CREATE_IF_NOT_EXISTS); |
| 247 | |
| 248 | asIScriptFunction *func = 0; |
| 249 | int r = mod->CompileFunction("addfunc", arg.c_str(), 0, asCOMP_ADD_TO_MODULE, &func); |
| 250 | if( r < 0 ) |
| 251 | { |
| 252 | // TODO: Add better description of error (invalid declaration, name conflict, etc) |
| 253 | cout << "Failed to add function. " << endl; |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | // The script engine supports function overloads, but to simplify the |
| 258 | // console we'll disallow multiple functions with the same name. |
| 259 | // We know the function was added, so if GetFunctionByName() fails it is |
| 260 | // because there already was another function with the same name. |
| 261 | if( mod->GetFunctionByName(func->GetName()) == 0 ) |
| 262 | { |
| 263 | mod->RemoveFunction(func); |
| 264 | cout << "Another function with that name already exists." << endl; |
| 265 | } |
| 266 | else |
| 267 | cout << "Function added. " << endl; |
| 268 | } |
| 269 | |
| 270 | // We must release the function object |
| 271 | if( func ) |
| 272 | func->Release(); |
| 273 | } |
| 274 | |
| 275 | void DeleteFunction(asIScriptEngine *engine, string &arg) |
| 276 | { |
no test coverage detected