| 437 | } |
| 438 | |
| 439 | bool cScriptingEngine::scriptRun(const std::string& pJS, const std::string& pFilename) { |
| 440 | int success = DUK_EXEC_ERROR; |
| 441 | |
| 442 | // Compile the JS into bytecode |
| 443 | duk_push_string(mContext, pFilename.c_str()); |
| 444 | if (duk_pcompile_string_filename(mContext, 0, pJS.c_str()) != 0) { |
| 445 | g_Debugger->Error("Compile failed: "); |
| 446 | } else { |
| 447 | |
| 448 | success = duk_pcall(mContext, 0); |
| 449 | if(success != DUK_EXEC_SUCCESS) |
| 450 | g_Debugger->Error("Execute failed: "); |
| 451 | } |
| 452 | |
| 453 | if (duk_is_error(mContext, -1)) { |
| 454 | duk_get_prop_string(mContext, -1, "stack"); |
| 455 | g_Debugger->Error(std::string(duk_safe_to_string(mContext, -1))); |
| 456 | } |
| 457 | else { |
| 458 | if (success != DUK_EXEC_SUCCESS) |
| 459 | g_Debugger->Error(std::string(duk_safe_to_string(mContext, -1))); |
| 460 | } |
| 461 | |
| 462 | duk_pop(mContext); |
| 463 | return (success == DUK_EXEC_SUCCESS); |
| 464 | } |
| 465 | |
| 466 | bool cScriptingEngine::Run(const std::string& pScript) { |
| 467 | |