Index: ps/trunk/source/gui/scripting/GuiScriptConversions.cpp =================================================================== --- ps/trunk/source/gui/scripting/GuiScriptConversions.cpp (revision 22846) +++ ps/trunk/source/gui/scripting/GuiScriptConversions.cpp (revision 22847) @@ -1,346 +1,356 @@ /* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "gui/CGUIColor.h" #include "gui/CGUIList.h" #include "gui/CGUISeries.h" #include "gui/GUIbase.h" #include "gui/IGUIObject.h" #include "lib/external_libraries/libsdl.h" #include "maths/Vector2D.h" #include "ps/Hotkey.h" #include "scriptinterface/ScriptConversions.h" #define SET(obj, name, value) STMT(JS::RootedValue v_(cx); AssignOrToJSVal(cx, &v_, (value)); JS_SetProperty(cx, obj, (name), v_)) // ignore JS_SetProperty return value, because errors should be impossible // and we can't do anything useful in the case of errors anyway template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, SDL_Event_ const& val) { JSAutoRequest rq(cx); const char* typeName; switch (val.ev.type) { case SDL_WINDOWEVENT: typeName = "windowevent"; break; case SDL_KEYDOWN: typeName = "keydown"; break; case SDL_KEYUP: typeName = "keyup"; break; case SDL_MOUSEMOTION: typeName = "mousemotion"; break; case SDL_MOUSEBUTTONDOWN: typeName = "mousebuttondown"; break; case SDL_MOUSEBUTTONUP: typeName = "mousebuttonup"; break; case SDL_QUIT: typeName = "quit"; break; case SDL_HOTKEYDOWN: typeName = "hotkeydown"; break; case SDL_HOTKEYUP: typeName = "hotkeyup"; break; default: typeName = "(unknown)"; break; } JS::RootedObject obj(cx, JS_NewPlainObject(cx)); if (!obj) { ret.setUndefined(); return; } SET(obj, "type", typeName); switch (val.ev.type) { case SDL_KEYDOWN: case SDL_KEYUP: { // SET(obj, "which", (int)val.ev.key.which); // (not in wsdl.h) // SET(obj, "state", (int)val.ev.key.state); // (not in wsdl.h) JS::RootedObject keysym(cx, JS_NewPlainObject(cx)); if (!keysym) { ret.setUndefined(); return; } JS::RootedValue keysymVal(cx, JS::ObjectValue(*keysym)); JS_SetProperty(cx, obj, "keysym", keysymVal); // SET(keysym, "scancode", (int)val.ev.key.keysym.scancode); // (not in wsdl.h) SET(keysym, "sym", (int)val.ev.key.keysym.sym); // SET(keysym, "mod", (int)val.ev.key.keysym.mod); // (not in wsdl.h) { SET(keysym, "unicode", JS::UndefinedHandleValue); } // TODO: scripts have no idea what all the key/mod enum values are; // we should probably expose them as constants if we expect scripts to use them break; } case SDL_MOUSEMOTION: { // SET(obj, "which", (int)val.ev.motion.which); // (not in wsdl.h) // SET(obj, "state", (int)val.ev.motion.state); // (not in wsdl.h) SET(obj, "x", (int)val.ev.motion.x); SET(obj, "y", (int)val.ev.motion.y); // SET(obj, "xrel", (int)val.ev.motion.xrel); // (not in wsdl.h) // SET(obj, "yrel", (int)val.ev.motion.yrel); // (not in wsdl.h) break; } case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { // SET(obj, "which", (int)val.ev.button.which); // (not in wsdl.h) SET(obj, "button", (int)val.ev.button.button); SET(obj, "state", (int)val.ev.button.state); SET(obj, "x", (int)val.ev.button.x); SET(obj, "y", (int)val.ev.button.y); SET(obj, "clicks", (int)val.ev.button.clicks); break; } case SDL_HOTKEYDOWN: case SDL_HOTKEYUP: { SET(obj, "hotkey", static_cast(val.ev.user.data1)); break; } } ret.setObject(*obj); } template<> void ScriptInterface::ToJSVal(JSContext* UNUSED(cx), JS::MutableHandleValue ret, IGUIObject* const& val) { if (val == NULL) ret.setNull(); else ret.setObject(*val->GetJSObject()); } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUIString& val) { ScriptInterface::ToJSVal(cx, ret, val.GetOriginalString()); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUIString& out) { std::wstring val; if (!FromJSVal(cx, v, val)) return false; out.SetValue(val); return true; } JSVAL_VECTOR(CVector2D) JSVAL_VECTOR(std::vector) JSVAL_VECTOR(CGUIString) template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUIColor& val) { ToJSVal(cx, ret, val); } /** * The color depends on the predefined color database stored in the current GUI page. */ template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUIColor& out) = delete; template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CSize& val) { ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject(ret, "width", val.cx, "height", val.cy); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CSize& out) { if (!v.isObject()) { JS_ReportError(cx, "CSize value must be an object!"); return false; } if (!FromJSProperty(cx, v, "width", out.cx)) { JS_ReportError(cx, "Failed to get CSize.cx property"); return false; } if (!FromJSProperty(cx, v, "height", out.cy)) { JS_ReportError(cx, "Failed to get CSize.cy property"); return false; } return true; } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CPos& val) { ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject(ret, "x", val.x, "y", val.y); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CPos& out) { if (!v.isObject()) { JS_ReportError(cx, "CPos value must be an object!"); return false; } if (!FromJSProperty(cx, v, "x", out.x)) { JS_ReportError(cx, "Failed to get CPos.x property"); return false; } if (!FromJSProperty(cx, v, "y", out.y)) { JS_ReportError(cx, "Failed to get CPos.y property"); return false; } return true; } +template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CRect& val) +{ + ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject( + ret, + "left", val.left, + "right", val.right, + "top", val.top, + "bottom", val.bottom); +} + template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CClientArea& val) { val.ToJSVal(cx, ret); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CClientArea& out) { return out.FromJSVal(cx, v); } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUIList& val) { ToJSVal(cx, ret, val.m_Items); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUIList& out) { return FromJSVal(cx, v, out.m_Items); } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUISeries& val) { ToJSVal(cx, ret, val.m_Series); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUISeries& out) { return FromJSVal(cx, v, out.m_Series); } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const EVAlign& val) { std::string word; switch (val) { case EVAlign_Top: word = "top"; break; case EVAlign_Bottom: word = "bottom"; break; case EVAlign_Center: word = "center"; break; default: word = "error"; JS_ReportError(cx, "Invalid EVAlign"); break; } ToJSVal(cx, ret, word); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, EVAlign& out) { std::string word; FromJSVal(cx, v, word); if (word == "top") out = EVAlign_Top; else if (word == "bottom") out = EVAlign_Bottom; else if (word == "center") out = EVAlign_Center; else { out = EVAlign_Top; JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); return false; } return true; } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const EAlign& val) { std::string word; switch (val) { case EAlign_Left: word = "left"; break; case EAlign_Right: word = "right"; break; case EAlign_Center: word = "center"; break; default: word = "error"; JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); break; } ToJSVal(cx, ret, word); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, EAlign& out) { std::string word; FromJSVal(cx, v, word); if (word == "left") out = EAlign_Left; else if (word == "right") out = EAlign_Right; else if (word == "center") out = EAlign_Center; else { out = EAlign_Left; JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); return false; } return true; } template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUISpriteInstance& val) { ToJSVal(cx, ret, val.GetName()); } template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUISpriteInstance& out) { std::string name; if (!FromJSVal(cx, v, name)) return false; out.SetName(name); return true; } #undef SET Index: ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp (revision 22846) +++ ps/trunk/source/gui/scripting/JSInterface_GUITypes.cpp (revision 22847) @@ -1,131 +1,125 @@ /* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "JSInterface_GUITypes.h" #include "ps/CStr.h" #include "scriptinterface/ScriptInterface.h" JSClass JSI_GUISize::JSI_class = { "GUISize", 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, JSI_GUISize::construct, nullptr }; JSFunctionSpec JSI_GUISize::JSI_methods[] = { JS_FN("toString", JSI_GUISize::toString, 0, 0), JS_FS_END }; bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize")); if (args.length() == 8) { JS_SetProperty(cx, obj, "left", args[0]); JS_SetProperty(cx, obj, "top", args[1]); JS_SetProperty(cx, obj, "right", args[2]); JS_SetProperty(cx, obj, "bottom", args[3]); JS_SetProperty(cx, obj, "rleft", args[4]); JS_SetProperty(cx, obj, "rtop", args[5]); JS_SetProperty(cx, obj, "rright", args[6]); JS_SetProperty(cx, obj, "rbottom", args[7]); } else if (args.length() == 4) { JS::RootedValue zero(cx, JS::NumberValue(0)); JS_SetProperty(cx, obj, "left", args[0]); JS_SetProperty(cx, obj, "top", args[1]); JS_SetProperty(cx, obj, "right", args[2]); JS_SetProperty(cx, obj, "bottom", args[3]); JS_SetProperty(cx, obj, "rleft", zero); JS_SetProperty(cx, obj, "rtop", zero); JS_SetProperty(cx, obj, "rright", zero); JS_SetProperty(cx, obj, "rbottom", zero); } else { JS::RootedValue zero(cx, JS::NumberValue(0)); JS_SetProperty(cx, obj, "left", zero); JS_SetProperty(cx, obj, "top", zero); JS_SetProperty(cx, obj, "right", zero); JS_SetProperty(cx, obj, "bottom", zero); JS_SetProperty(cx, obj, "rleft", zero); JS_SetProperty(cx, obj, "rtop", zero); JS_SetProperty(cx, obj, "rright", zero); JS_SetProperty(cx, obj, "rbottom", zero); } args.rval().setObject(*obj); return true; } // Produces "10", "-10", "50%", "50%-10", "50%+10", etc CStr ToPercentString(double pix, double per) { if (per == 0) return CStr::FromDouble(pix); return CStr::FromDouble(per)+"%"+(pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix)); } bool JSI_GUISize::toString(JSContext* cx, uint argc, JS::Value* vp) { // JSAutoRequest not needed for the calls below JS::CallArgs args = JS::CallArgsFromVp(argc, vp); CStr buffer; - try - { - ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; - double val, valr; + ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; + double val, valr; + #define SIDE(side) \ pScriptInterface->GetProperty(args.thisv(), #side, val); \ pScriptInterface->GetProperty(args.thisv(), "r"#side, valr); \ buffer += ToPercentString(val, valr); - SIDE(left); - buffer += " "; - SIDE(top); - buffer += " "; - SIDE(right); - buffer += " "; - SIDE(bottom); + SIDE(left); + buffer += " "; + SIDE(top); + buffer += " "; + SIDE(right); + buffer += " "; + SIDE(bottom); #undef SIDE - } - catch (PSERROR_Scripting_ConversionFailed&) - { - ScriptInterface::ToJSVal(cx, args.rval(), std::string("")); - return true; - } + ScriptInterface::ToJSVal(cx, args.rval(), buffer); return true; } void JSI_GUITypes::init(ScriptInterface& scriptInterface) { scriptInterface.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 1, nullptr, JSI_GUISize::JSI_methods, NULL, NULL); } Index: ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp (revision 22846) +++ ps/trunk/source/gui/scripting/JSInterface_IGUIObject.cpp (revision 22847) @@ -1,251 +1,234 @@ /* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "JSInterface_IGUIObject.h" #include "gui/CGUI.h" #include "gui/CGUIColor.h" #include "gui/CGUISetting.h" #include "gui/CList.h" #include "gui/GUIManager.h" #include "gui/IGUIObject.h" #include "gui/IGUIScrollBar.h" #include "gui/scripting/JSInterface_GUITypes.h" #include "ps/CLogger.h" #include "scriptinterface/ScriptExtraHeaders.h" #include "scriptinterface/ScriptInterface.h" JSClass JSI_IGUIObject::JSI_class = { "GUIObject", JSCLASS_HAS_PRIVATE, nullptr, nullptr, JSI_IGUIObject::getProperty, JSI_IGUIObject::setProperty, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }; JSFunctionSpec JSI_IGUIObject::JSI_methods[] = { JS_FN("toString", JSI_IGUIObject::toString, 0, 0), JS_FN("focus", JSI_IGUIObject::focus, 0, 0), JS_FN("blur", JSI_IGUIObject::blur, 0, 0), JS_FN("getComputedSize", JSI_IGUIObject::getComputedSize, 0, 0), JS_FS_END }; bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp) { JSAutoRequest rq(cx); ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; IGUIObject* e = ScriptInterface::GetPrivate(cx, obj, &JSI_IGUIObject::JSI_class); if (!e) return false; JS::RootedValue idval(cx); if (!JS_IdToValue(cx, id, &idval)) return false; std::string propName; if (!ScriptInterface::FromJSVal(cx, idval, propName)) return false; // Skip registered functions and inherited properties // including JSInterfaces of derived classes if (propName == "constructor" || propName == "prototype" || propName == "toString" || propName == "toJSON" || propName == "focus" || propName == "blur" || propName == "getTextSize" || propName == "getComputedSize" ) return true; // Use onWhatever to access event handlers if (propName.substr(0, 2) == "on") { CStr eventName(CStr(propName.substr(2)).LowerCase()); std::map>::iterator it = e->m_ScriptHandlers.find(eventName); if (it == e->m_ScriptHandlers.end()) vp.setNull(); else vp.setObject(*it->second.get()); return true; } if (propName == "parent") { IGUIObject* parent = e->GetParent(); if (parent) vp.set(JS::ObjectValue(*parent->GetJSObject())); else vp.set(JS::NullValue()); return true; } else if (propName == "children") { pScriptInterface->CreateArray(vp); for (size_t i = 0; i < e->m_Children.size(); ++i) pScriptInterface->SetPropertyInt(vp, i, e->m_Children[i]); return true; } else if (propName == "name") { ScriptInterface::ToJSVal(cx, vp, e->GetName()); return true; } else if (e->SettingExists(propName)) { e->m_Settings[propName]->ToJSVal(cx, vp); return true; } JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str()); return false; } bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result) { IGUIObject* e = ScriptInterface::GetPrivate(cx, obj, &JSI_IGUIObject::JSI_class); if (!e) return result.fail(JSMSG_NOT_NONNULL_OBJECT); JSAutoRequest rq(cx); JS::RootedValue idval(cx); if (!JS_IdToValue(cx, id, &idval)) return result.fail(JSMSG_NOT_NONNULL_OBJECT); std::string propName; if (!ScriptInterface::FromJSVal(cx, idval, propName)) return result.fail(JSMSG_UNDEFINED_PROP); if (propName == "name") { std::string value; if (!ScriptInterface::FromJSVal(cx, vp, value)) return result.fail(JSMSG_UNDEFINED_PROP); e->SetName(value); return result.succeed(); } JS::RootedObject vpObj(cx); if (vp.isObject()) vpObj = &vp.toObject(); // Use onWhatever to set event handlers if (propName.substr(0, 2) == "on") { if (vp.isPrimitive() || vp.isNull() || !JS_ObjectIsFunction(cx, &vp.toObject())) { JS_ReportError(cx, "on- event-handlers must be functions"); return result.fail(JSMSG_NOT_FUNCTION); } CStr eventName(CStr(propName.substr(2)).LowerCase()); e->SetScriptHandler(eventName, vpObj); return result.succeed(); } if (e->SettingExists(propName)) return e->m_Settings[propName]->FromJSVal(cx, vp, true) ? result.succeed() : result.fail(JSMSG_TYPE_ERR_BAD_ARGS); JS_ReportError(cx, "Property '%s' does not exist!", propName.c_str()); return result.fail(JSMSG_UNDEFINED_PROP); } void JSI_IGUIObject::init(ScriptInterface& scriptInterface) { scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 1, nullptr, JSI_methods, nullptr, nullptr); } bool JSI_IGUIObject::toString(JSContext* cx, uint argc, JS::Value* vp) { // No JSAutoRequest needed for these calls JS::CallArgs args = JS::CallArgsFromVp(argc, vp); IGUIObject* e = ScriptInterface::GetPrivate(cx, args, &JSI_IGUIObject::JSI_class); if (!e) return false; ScriptInterface::ToJSVal(cx, args.rval(), "[GUIObject: " + e->GetName() + "]"); return true; } bool JSI_IGUIObject::focus(JSContext* cx, uint argc, JS::Value* vp) { // No JSAutoRequest needed for these calls JS::CallArgs args = JS::CallArgsFromVp(argc, vp); IGUIObject* e = ScriptInterface::GetPrivate(cx, args, &JSI_IGUIObject::JSI_class); if (!e) return false; e->GetGUI().SetFocusedObject(e); args.rval().setUndefined(); return true; } bool JSI_IGUIObject::blur(JSContext* cx, uint argc, JS::Value* vp) { // No JSAutoRequest needed for these calls JS::CallArgs args = JS::CallArgsFromVp(argc, vp); IGUIObject* e = ScriptInterface::GetPrivate(cx, args, &JSI_IGUIObject::JSI_class); if (!e) return false; e->GetGUI().SetFocusedObject(nullptr); args.rval().setUndefined(); return true; } bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp) { JSAutoRequest rq(cx); JS::CallArgs args = JS::CallArgsFromVp(argc, vp); IGUIObject* e = ScriptInterface::GetPrivate(cx, args, &JSI_IGUIObject::JSI_class); if (!e) return false; e->UpdateCachedSize(); - CRect size = e->m_CachedActualSize; + ScriptInterface::ToJSVal(cx, args.rval(), e->m_CachedActualSize); - JS::RootedValue objVal(cx); - try - { - ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface->CreateObject( - &objVal, - "left", size.left, - "right", size.right, - "top", size.top, - "bottom", size.bottom); - } - catch (PSERROR_Scripting_ConversionFailed&) - { - debug_warn(L"Error creating size object!"); - return false; - } - - args.rval().set(objVal); return true; } Index: ps/trunk/source/ps/Errors.cpp =================================================================== --- ps/trunk/source/ps/Errors.cpp (revision 22846) +++ ps/trunk/source/ps/Errors.cpp (revision 22847) @@ -1,514 +1,504 @@ // Auto-generated by errorlist.pl - do not edit. #include "precompiled.h" #include "Errors.h" class PSERROR_CVFSFile : public PSERROR { protected: PSERROR_CVFSFile(const char* msg); }; class PSERROR_Deserialize : public PSERROR { protected: PSERROR_Deserialize(const char* msg); }; class PSERROR_DllLoader : public PSERROR { protected: PSERROR_DllLoader(const char* msg); }; class PSERROR_Error : public PSERROR { protected: PSERROR_Error(const char* msg); }; class PSERROR_File : public PSERROR { protected: PSERROR_File(const char* msg); }; class PSERROR_GUI : public PSERROR { protected: PSERROR_GUI(const char* msg); }; class PSERROR_Game : public PSERROR { protected: PSERROR_Game(const char* msg); }; class PSERROR_Scripting : public PSERROR { protected: PSERROR_Scripting(const char* msg); }; class PSERROR_Serialize : public PSERROR { protected: PSERROR_Serialize(const char* msg); }; class PSERROR_System : public PSERROR { protected: PSERROR_System(const char* msg); }; class PSERROR_Xeromyces : public PSERROR { protected: PSERROR_Xeromyces(const char* msg); }; class PSERROR_Game_World : public PSERROR_Game { protected: PSERROR_Game_World(const char* msg); }; class PSERROR_Scripting_DefineType : public PSERROR_Scripting { protected: PSERROR_Scripting_DefineType(const char* msg); }; class PSERROR_Scripting_LoadFile : public PSERROR_Scripting { protected: PSERROR_Scripting_LoadFile(const char* msg); }; class PSERROR_CVFSFile_AlreadyLoaded : public PSERROR_CVFSFile { public: PSERROR_CVFSFile_AlreadyLoaded(); PSERROR_CVFSFile_AlreadyLoaded(const char* msg); PSRETURN getCode() const; }; class PSERROR_CVFSFile_LoadFailed : public PSERROR_CVFSFile { public: PSERROR_CVFSFile_LoadFailed(); PSERROR_CVFSFile_LoadFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Deserialize_InvalidCharInString : public PSERROR_Deserialize { public: PSERROR_Deserialize_InvalidCharInString(); PSERROR_Deserialize_InvalidCharInString(const char* msg); PSRETURN getCode() const; }; class PSERROR_Deserialize_OutOfBounds : public PSERROR_Deserialize { public: PSERROR_Deserialize_OutOfBounds(); PSERROR_Deserialize_OutOfBounds(const char* msg); PSRETURN getCode() const; }; class PSERROR_Deserialize_ReadFailed : public PSERROR_Deserialize { public: PSERROR_Deserialize_ReadFailed(); PSERROR_Deserialize_ReadFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Deserialize_ScriptError : public PSERROR_Deserialize { public: PSERROR_Deserialize_ScriptError(); PSERROR_Deserialize_ScriptError(const char* msg); PSRETURN getCode() const; }; class PSERROR_DllLoader_DllNotLoaded : public PSERROR_DllLoader { public: PSERROR_DllLoader_DllNotLoaded(); PSERROR_DllLoader_DllNotLoaded(const char* msg); PSRETURN getCode() const; }; class PSERROR_DllLoader_SymbolNotFound : public PSERROR_DllLoader { public: PSERROR_DllLoader_SymbolNotFound(); PSERROR_DllLoader_SymbolNotFound(const char* msg); PSRETURN getCode() const; }; class PSERROR_Error_InvalidError : public PSERROR_Error { public: PSERROR_Error_InvalidError(); PSERROR_Error_InvalidError(const char* msg); PSRETURN getCode() const; }; class PSERROR_File_InvalidType : public PSERROR_File { public: PSERROR_File_InvalidType(); PSERROR_File_InvalidType(const char* msg); PSRETURN getCode() const; }; class PSERROR_File_InvalidVersion : public PSERROR_File { public: PSERROR_File_InvalidVersion(); PSERROR_File_InvalidVersion(const char* msg); PSRETURN getCode() const; }; class PSERROR_File_OpenFailed : public PSERROR_File { public: PSERROR_File_OpenFailed(); PSERROR_File_OpenFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_File_ReadFailed : public PSERROR_File { public: PSERROR_File_ReadFailed(); PSERROR_File_ReadFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_File_UnexpectedEOF : public PSERROR_File { public: PSERROR_File_UnexpectedEOF(); PSERROR_File_UnexpectedEOF(const char* msg); PSRETURN getCode() const; }; class PSERROR_File_WriteFailed : public PSERROR_File { public: PSERROR_File_WriteFailed(); PSERROR_File_WriteFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_GUI_InvalidSetting : public PSERROR_GUI { public: PSERROR_GUI_InvalidSetting(); PSERROR_GUI_InvalidSetting(const char* msg); PSRETURN getCode() const; }; class PSERROR_GUI_JSOpenFailed : public PSERROR_GUI { public: PSERROR_GUI_JSOpenFailed(); PSERROR_GUI_JSOpenFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_GUI_NameAmbiguity : public PSERROR_GUI { public: PSERROR_GUI_NameAmbiguity(); PSERROR_GUI_NameAmbiguity(const char* msg); PSRETURN getCode() const; }; class PSERROR_GUI_ObjectNeedsName : public PSERROR_GUI { public: PSERROR_GUI_ObjectNeedsName(); PSERROR_GUI_ObjectNeedsName(const char* msg); PSRETURN getCode() const; }; class PSERROR_GUI_OperationNeedsGUIObject : public PSERROR_GUI { public: PSERROR_GUI_OperationNeedsGUIObject(); PSERROR_GUI_OperationNeedsGUIObject(const char* msg); PSRETURN getCode() const; }; class PSERROR_GUI_UnableToParse : public PSERROR_GUI { public: PSERROR_GUI_UnableToParse(); PSERROR_GUI_UnableToParse(const char* msg); PSRETURN getCode() const; }; class PSERROR_Game_World_MapLoadFailed : public PSERROR_Game_World { public: PSERROR_Game_World_MapLoadFailed(); PSERROR_Game_World_MapLoadFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_CallFunctionFailed : public PSERROR_Scripting { public: PSERROR_Scripting_CallFunctionFailed(); PSERROR_Scripting_CallFunctionFailed(const char* msg); PSRETURN getCode() const; }; -class PSERROR_Scripting_ConversionFailed : public PSERROR_Scripting { public: PSERROR_Scripting_ConversionFailed(); PSERROR_Scripting_ConversionFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_CreateObjectFailed : public PSERROR_Scripting { public: PSERROR_Scripting_CreateObjectFailed(); PSERROR_Scripting_CreateObjectFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_DefineConstantFailed : public PSERROR_Scripting { public: PSERROR_Scripting_DefineConstantFailed(); PSERROR_Scripting_DefineConstantFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_DefineType_AlreadyExists : public PSERROR_Scripting_DefineType { public: PSERROR_Scripting_DefineType_AlreadyExists(); PSERROR_Scripting_DefineType_AlreadyExists(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_DefineType_CreationFailed : public PSERROR_Scripting_DefineType { public: PSERROR_Scripting_DefineType_CreationFailed(); PSERROR_Scripting_DefineType_CreationFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_LoadFile_EvalErrors : public PSERROR_Scripting_LoadFile { public: PSERROR_Scripting_LoadFile_EvalErrors(); PSERROR_Scripting_LoadFile_EvalErrors(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_LoadFile_OpenFailed : public PSERROR_Scripting_LoadFile { public: PSERROR_Scripting_LoadFile_OpenFailed(); PSERROR_Scripting_LoadFile_OpenFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_RegisterFunctionFailed : public PSERROR_Scripting { public: PSERROR_Scripting_RegisterFunctionFailed(); PSERROR_Scripting_RegisterFunctionFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_SetupFailed : public PSERROR_Scripting { public: PSERROR_Scripting_SetupFailed(); PSERROR_Scripting_SetupFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Scripting_TypeDoesNotExist : public PSERROR_Scripting { public: PSERROR_Scripting_TypeDoesNotExist(); PSERROR_Scripting_TypeDoesNotExist(const char* msg); PSRETURN getCode() const; }; class PSERROR_Serialize_InvalidCharInString : public PSERROR_Serialize { public: PSERROR_Serialize_InvalidCharInString(); PSERROR_Serialize_InvalidCharInString(const char* msg); PSRETURN getCode() const; }; class PSERROR_Serialize_InvalidScriptValue : public PSERROR_Serialize { public: PSERROR_Serialize_InvalidScriptValue(); PSERROR_Serialize_InvalidScriptValue(const char* msg); PSRETURN getCode() const; }; class PSERROR_Serialize_OutOfBounds : public PSERROR_Serialize { public: PSERROR_Serialize_OutOfBounds(); PSERROR_Serialize_OutOfBounds(const char* msg); PSRETURN getCode() const; }; class PSERROR_Serialize_ScriptError : public PSERROR_Serialize { public: PSERROR_Serialize_ScriptError(); PSERROR_Serialize_ScriptError(const char* msg); PSRETURN getCode() const; }; class PSERROR_System_RequiredExtensionsMissing : public PSERROR_System { public: PSERROR_System_RequiredExtensionsMissing(); PSERROR_System_RequiredExtensionsMissing(const char* msg); PSRETURN getCode() const; }; class PSERROR_System_SDLInitFailed : public PSERROR_System { public: PSERROR_System_SDLInitFailed(); PSERROR_System_SDLInitFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_System_VmodeFailed : public PSERROR_System { public: PSERROR_System_VmodeFailed(); PSERROR_System_VmodeFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Xeromyces_XMLOpenFailed : public PSERROR_Xeromyces { public: PSERROR_Xeromyces_XMLOpenFailed(); PSERROR_Xeromyces_XMLOpenFailed(const char* msg); PSRETURN getCode() const; }; class PSERROR_Xeromyces_XMLParseError : public PSERROR_Xeromyces { public: PSERROR_Xeromyces_XMLParseError(); PSERROR_Xeromyces_XMLParseError(const char* msg); PSRETURN getCode() const; }; extern const PSRETURN PSRETURN_CVFSFile_AlreadyLoaded = 0x01000001; extern const PSRETURN PSRETURN_CVFSFile_LoadFailed = 0x01000002; extern const PSRETURN PSRETURN_Deserialize_InvalidCharInString = 0x02000001; extern const PSRETURN PSRETURN_Deserialize_OutOfBounds = 0x02000002; extern const PSRETURN PSRETURN_Deserialize_ReadFailed = 0x02000003; extern const PSRETURN PSRETURN_Deserialize_ScriptError = 0x02000004; extern const PSRETURN PSRETURN_DllLoader_DllNotLoaded = 0x03000001; extern const PSRETURN PSRETURN_DllLoader_SymbolNotFound = 0x03000002; extern const PSRETURN PSRETURN_Error_InvalidError = 0x04000001; extern const PSRETURN PSRETURN_File_InvalidType = 0x05000001; extern const PSRETURN PSRETURN_File_InvalidVersion = 0x05000002; extern const PSRETURN PSRETURN_File_OpenFailed = 0x05000003; extern const PSRETURN PSRETURN_File_ReadFailed = 0x05000004; extern const PSRETURN PSRETURN_File_UnexpectedEOF = 0x05000005; extern const PSRETURN PSRETURN_File_WriteFailed = 0x05000006; extern const PSRETURN PSRETURN_GUI_InvalidSetting = 0x06000001; extern const PSRETURN PSRETURN_GUI_JSOpenFailed = 0x06000002; extern const PSRETURN PSRETURN_GUI_NameAmbiguity = 0x06000003; extern const PSRETURN PSRETURN_GUI_ObjectNeedsName = 0x06000004; extern const PSRETURN PSRETURN_GUI_OperationNeedsGUIObject = 0x06000005; extern const PSRETURN PSRETURN_GUI_UnableToParse = 0x06000006; extern const PSRETURN PSRETURN_Game_World_MapLoadFailed = 0x07030001; extern const PSRETURN PSRETURN_Scripting_DefineType_AlreadyExists = 0x08010001; extern const PSRETURN PSRETURN_Scripting_DefineType_CreationFailed = 0x08010002; extern const PSRETURN PSRETURN_Scripting_LoadFile_EvalErrors = 0x08020001; extern const PSRETURN PSRETURN_Scripting_LoadFile_OpenFailed = 0x08020002; extern const PSRETURN PSRETURN_Scripting_CallFunctionFailed = 0x08000001; -extern const PSRETURN PSRETURN_Scripting_ConversionFailed = 0x08000002; -extern const PSRETURN PSRETURN_Scripting_CreateObjectFailed = 0x08000003; -extern const PSRETURN PSRETURN_Scripting_DefineConstantFailed = 0x08000004; -extern const PSRETURN PSRETURN_Scripting_RegisterFunctionFailed = 0x08000005; -extern const PSRETURN PSRETURN_Scripting_SetupFailed = 0x08000006; -extern const PSRETURN PSRETURN_Scripting_TypeDoesNotExist = 0x08000007; +extern const PSRETURN PSRETURN_Scripting_CreateObjectFailed = 0x08000002; +extern const PSRETURN PSRETURN_Scripting_DefineConstantFailed = 0x08000003; +extern const PSRETURN PSRETURN_Scripting_RegisterFunctionFailed = 0x08000004; +extern const PSRETURN PSRETURN_Scripting_SetupFailed = 0x08000005; +extern const PSRETURN PSRETURN_Scripting_TypeDoesNotExist = 0x08000006; extern const PSRETURN PSRETURN_Serialize_InvalidCharInString = 0x09000001; extern const PSRETURN PSRETURN_Serialize_InvalidScriptValue = 0x09000002; extern const PSRETURN PSRETURN_Serialize_OutOfBounds = 0x09000003; extern const PSRETURN PSRETURN_Serialize_ScriptError = 0x09000004; extern const PSRETURN PSRETURN_System_RequiredExtensionsMissing = 0x0a000001; extern const PSRETURN PSRETURN_System_SDLInitFailed = 0x0a000002; extern const PSRETURN PSRETURN_System_VmodeFailed = 0x0a000003; extern const PSRETURN PSRETURN_Xeromyces_XMLOpenFailed = 0x0b000001; extern const PSRETURN PSRETURN_Xeromyces_XMLParseError = 0x0b000002; extern const PSRETURN MASK__PSRETURN_CVFSFile = 0xff000000; extern const PSRETURN CODE__PSRETURN_CVFSFile = 0x01000000; extern const PSRETURN MASK__PSRETURN_Deserialize = 0xff000000; extern const PSRETURN CODE__PSRETURN_Deserialize = 0x02000000; extern const PSRETURN MASK__PSRETURN_DllLoader = 0xff000000; extern const PSRETURN CODE__PSRETURN_DllLoader = 0x03000000; extern const PSRETURN MASK__PSRETURN_Error = 0xff000000; extern const PSRETURN CODE__PSRETURN_Error = 0x04000000; extern const PSRETURN MASK__PSRETURN_File = 0xff000000; extern const PSRETURN CODE__PSRETURN_File = 0x05000000; extern const PSRETURN MASK__PSRETURN_GUI = 0xff000000; extern const PSRETURN CODE__PSRETURN_GUI = 0x06000000; extern const PSRETURN MASK__PSRETURN_Game = 0xff000000; extern const PSRETURN CODE__PSRETURN_Game = 0x07000000; extern const PSRETURN MASK__PSRETURN_Scripting = 0xff000000; extern const PSRETURN CODE__PSRETURN_Scripting = 0x08000000; extern const PSRETURN MASK__PSRETURN_Serialize = 0xff000000; extern const PSRETURN CODE__PSRETURN_Serialize = 0x09000000; extern const PSRETURN MASK__PSRETURN_System = 0x0a000000; extern const PSRETURN CODE__PSRETURN_System = 0x0a000000; extern const PSRETURN MASK__PSRETURN_Xeromyces = 0x0b000000; extern const PSRETURN CODE__PSRETURN_Xeromyces = 0x0b000000; extern const PSRETURN MASK__PSRETURN_Game_World = 0xffff0000; extern const PSRETURN CODE__PSRETURN_Game_World = 0x07030000; extern const PSRETURN MASK__PSRETURN_Scripting_DefineType = 0xffff0000; extern const PSRETURN CODE__PSRETURN_Scripting_DefineType = 0x08010000; extern const PSRETURN MASK__PSRETURN_Scripting_LoadFile = 0xffff0000; extern const PSRETURN CODE__PSRETURN_Scripting_LoadFile = 0x08020000; extern const PSRETURN MASK__PSRETURN_CVFSFile_AlreadyLoaded = 0xffffffff; extern const PSRETURN CODE__PSRETURN_CVFSFile_AlreadyLoaded = 0x01000001; extern const PSRETURN MASK__PSRETURN_CVFSFile_LoadFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_CVFSFile_LoadFailed = 0x01000002; extern const PSRETURN MASK__PSRETURN_Deserialize_InvalidCharInString = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Deserialize_InvalidCharInString = 0x02000001; extern const PSRETURN MASK__PSRETURN_Deserialize_OutOfBounds = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Deserialize_OutOfBounds = 0x02000002; extern const PSRETURN MASK__PSRETURN_Deserialize_ReadFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Deserialize_ReadFailed = 0x02000003; extern const PSRETURN MASK__PSRETURN_Deserialize_ScriptError = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Deserialize_ScriptError = 0x02000004; extern const PSRETURN MASK__PSRETURN_DllLoader_DllNotLoaded = 0xffffffff; extern const PSRETURN CODE__PSRETURN_DllLoader_DllNotLoaded = 0x03000001; extern const PSRETURN MASK__PSRETURN_DllLoader_SymbolNotFound = 0xffffffff; extern const PSRETURN CODE__PSRETURN_DllLoader_SymbolNotFound = 0x03000002; extern const PSRETURN MASK__PSRETURN_Error_InvalidError = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Error_InvalidError = 0x04000001; extern const PSRETURN MASK__PSRETURN_File_InvalidType = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_InvalidType = 0x05000001; extern const PSRETURN MASK__PSRETURN_File_InvalidVersion = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_InvalidVersion = 0x05000002; extern const PSRETURN MASK__PSRETURN_File_OpenFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_OpenFailed = 0x05000003; extern const PSRETURN MASK__PSRETURN_File_ReadFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_ReadFailed = 0x05000004; extern const PSRETURN MASK__PSRETURN_File_UnexpectedEOF = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_UnexpectedEOF = 0x05000005; extern const PSRETURN MASK__PSRETURN_File_WriteFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_File_WriteFailed = 0x05000006; extern const PSRETURN MASK__PSRETURN_GUI_InvalidSetting = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_InvalidSetting = 0x06000001; extern const PSRETURN MASK__PSRETURN_GUI_JSOpenFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_JSOpenFailed = 0x06000002; extern const PSRETURN MASK__PSRETURN_GUI_NameAmbiguity = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_NameAmbiguity = 0x06000003; extern const PSRETURN MASK__PSRETURN_GUI_ObjectNeedsName = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_ObjectNeedsName = 0x06000004; extern const PSRETURN MASK__PSRETURN_GUI_OperationNeedsGUIObject = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_OperationNeedsGUIObject = 0x06000005; extern const PSRETURN MASK__PSRETURN_GUI_UnableToParse = 0xffffffff; extern const PSRETURN CODE__PSRETURN_GUI_UnableToParse = 0x06000006; extern const PSRETURN MASK__PSRETURN_Game_World_MapLoadFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Game_World_MapLoadFailed = 0x07030001; extern const PSRETURN MASK__PSRETURN_Scripting_DefineType_AlreadyExists = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Scripting_DefineType_AlreadyExists = 0x08010001; extern const PSRETURN MASK__PSRETURN_Scripting_DefineType_CreationFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Scripting_DefineType_CreationFailed = 0x08010002; extern const PSRETURN MASK__PSRETURN_Scripting_LoadFile_EvalErrors = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Scripting_LoadFile_EvalErrors = 0x08020001; extern const PSRETURN MASK__PSRETURN_Scripting_LoadFile_OpenFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Scripting_LoadFile_OpenFailed = 0x08020002; extern const PSRETURN MASK__PSRETURN_Scripting_CallFunctionFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Scripting_CallFunctionFailed = 0x08000001; -extern const PSRETURN MASK__PSRETURN_Scripting_ConversionFailed = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_Scripting_ConversionFailed = 0x08000002; extern const PSRETURN MASK__PSRETURN_Scripting_CreateObjectFailed = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_Scripting_CreateObjectFailed = 0x08000003; +extern const PSRETURN CODE__PSRETURN_Scripting_CreateObjectFailed = 0x08000002; extern const PSRETURN MASK__PSRETURN_Scripting_DefineConstantFailed = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_Scripting_DefineConstantFailed = 0x08000004; +extern const PSRETURN CODE__PSRETURN_Scripting_DefineConstantFailed = 0x08000003; extern const PSRETURN MASK__PSRETURN_Scripting_RegisterFunctionFailed = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_Scripting_RegisterFunctionFailed = 0x08000005; +extern const PSRETURN CODE__PSRETURN_Scripting_RegisterFunctionFailed = 0x08000004; extern const PSRETURN MASK__PSRETURN_Scripting_SetupFailed = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_Scripting_SetupFailed = 0x08000006; +extern const PSRETURN CODE__PSRETURN_Scripting_SetupFailed = 0x08000005; extern const PSRETURN MASK__PSRETURN_Scripting_TypeDoesNotExist = 0xffffffff; -extern const PSRETURN CODE__PSRETURN_Scripting_TypeDoesNotExist = 0x08000007; +extern const PSRETURN CODE__PSRETURN_Scripting_TypeDoesNotExist = 0x08000006; extern const PSRETURN MASK__PSRETURN_Serialize_InvalidCharInString = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Serialize_InvalidCharInString = 0x09000001; extern const PSRETURN MASK__PSRETURN_Serialize_InvalidScriptValue = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Serialize_InvalidScriptValue = 0x09000002; extern const PSRETURN MASK__PSRETURN_Serialize_OutOfBounds = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Serialize_OutOfBounds = 0x09000003; extern const PSRETURN MASK__PSRETURN_Serialize_ScriptError = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Serialize_ScriptError = 0x09000004; extern const PSRETURN MASK__PSRETURN_System_RequiredExtensionsMissing = 0xffffffff; extern const PSRETURN CODE__PSRETURN_System_RequiredExtensionsMissing = 0x0a000001; extern const PSRETURN MASK__PSRETURN_System_SDLInitFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_System_SDLInitFailed = 0x0a000002; extern const PSRETURN MASK__PSRETURN_System_VmodeFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_System_VmodeFailed = 0x0a000003; extern const PSRETURN MASK__PSRETURN_Xeromyces_XMLOpenFailed = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Xeromyces_XMLOpenFailed = 0x0b000001; extern const PSRETURN MASK__PSRETURN_Xeromyces_XMLParseError = 0xffffffff; extern const PSRETURN CODE__PSRETURN_Xeromyces_XMLParseError = 0x0b000002; PSERROR_CVFSFile::PSERROR_CVFSFile(const char* msg) : PSERROR(msg) { } PSERROR_Deserialize::PSERROR_Deserialize(const char* msg) : PSERROR(msg) { } PSERROR_DllLoader::PSERROR_DllLoader(const char* msg) : PSERROR(msg) { } PSERROR_Error::PSERROR_Error(const char* msg) : PSERROR(msg) { } PSERROR_File::PSERROR_File(const char* msg) : PSERROR(msg) { } PSERROR_GUI::PSERROR_GUI(const char* msg) : PSERROR(msg) { } PSERROR_Game::PSERROR_Game(const char* msg) : PSERROR(msg) { } PSERROR_Scripting::PSERROR_Scripting(const char* msg) : PSERROR(msg) { } PSERROR_Serialize::PSERROR_Serialize(const char* msg) : PSERROR(msg) { } PSERROR_System::PSERROR_System(const char* msg) : PSERROR(msg) { } PSERROR_Xeromyces::PSERROR_Xeromyces(const char* msg) : PSERROR(msg) { } PSERROR_Game_World::PSERROR_Game_World(const char* msg) : PSERROR_Game(msg) { } PSERROR_Scripting_DefineType::PSERROR_Scripting_DefineType(const char* msg) : PSERROR_Scripting(msg) { } PSERROR_Scripting_LoadFile::PSERROR_Scripting_LoadFile(const char* msg) : PSERROR_Scripting(msg) { } PSERROR_CVFSFile_AlreadyLoaded::PSERROR_CVFSFile_AlreadyLoaded() : PSERROR_CVFSFile(NULL) { } PSERROR_CVFSFile_AlreadyLoaded::PSERROR_CVFSFile_AlreadyLoaded(const char* msg) : PSERROR_CVFSFile(msg) { } PSRETURN PSERROR_CVFSFile_AlreadyLoaded::getCode() const { return 0x01000001; } PSERROR_CVFSFile_LoadFailed::PSERROR_CVFSFile_LoadFailed() : PSERROR_CVFSFile(NULL) { } PSERROR_CVFSFile_LoadFailed::PSERROR_CVFSFile_LoadFailed(const char* msg) : PSERROR_CVFSFile(msg) { } PSRETURN PSERROR_CVFSFile_LoadFailed::getCode() const { return 0x01000002; } PSERROR_Deserialize_InvalidCharInString::PSERROR_Deserialize_InvalidCharInString() : PSERROR_Deserialize(NULL) { } PSERROR_Deserialize_InvalidCharInString::PSERROR_Deserialize_InvalidCharInString(const char* msg) : PSERROR_Deserialize(msg) { } PSRETURN PSERROR_Deserialize_InvalidCharInString::getCode() const { return 0x02000001; } PSERROR_Deserialize_OutOfBounds::PSERROR_Deserialize_OutOfBounds() : PSERROR_Deserialize(NULL) { } PSERROR_Deserialize_OutOfBounds::PSERROR_Deserialize_OutOfBounds(const char* msg) : PSERROR_Deserialize(msg) { } PSRETURN PSERROR_Deserialize_OutOfBounds::getCode() const { return 0x02000002; } PSERROR_Deserialize_ReadFailed::PSERROR_Deserialize_ReadFailed() : PSERROR_Deserialize(NULL) { } PSERROR_Deserialize_ReadFailed::PSERROR_Deserialize_ReadFailed(const char* msg) : PSERROR_Deserialize(msg) { } PSRETURN PSERROR_Deserialize_ReadFailed::getCode() const { return 0x02000003; } PSERROR_Deserialize_ScriptError::PSERROR_Deserialize_ScriptError() : PSERROR_Deserialize(NULL) { } PSERROR_Deserialize_ScriptError::PSERROR_Deserialize_ScriptError(const char* msg) : PSERROR_Deserialize(msg) { } PSRETURN PSERROR_Deserialize_ScriptError::getCode() const { return 0x02000004; } PSERROR_DllLoader_DllNotLoaded::PSERROR_DllLoader_DllNotLoaded() : PSERROR_DllLoader(NULL) { } PSERROR_DllLoader_DllNotLoaded::PSERROR_DllLoader_DllNotLoaded(const char* msg) : PSERROR_DllLoader(msg) { } PSRETURN PSERROR_DllLoader_DllNotLoaded::getCode() const { return 0x03000001; } PSERROR_DllLoader_SymbolNotFound::PSERROR_DllLoader_SymbolNotFound() : PSERROR_DllLoader(NULL) { } PSERROR_DllLoader_SymbolNotFound::PSERROR_DllLoader_SymbolNotFound(const char* msg) : PSERROR_DllLoader(msg) { } PSRETURN PSERROR_DllLoader_SymbolNotFound::getCode() const { return 0x03000002; } PSERROR_Error_InvalidError::PSERROR_Error_InvalidError() : PSERROR_Error(NULL) { } PSERROR_Error_InvalidError::PSERROR_Error_InvalidError(const char* msg) : PSERROR_Error(msg) { } PSRETURN PSERROR_Error_InvalidError::getCode() const { return 0x04000001; } PSERROR_File_InvalidType::PSERROR_File_InvalidType() : PSERROR_File(NULL) { } PSERROR_File_InvalidType::PSERROR_File_InvalidType(const char* msg) : PSERROR_File(msg) { } PSRETURN PSERROR_File_InvalidType::getCode() const { return 0x05000001; } PSERROR_File_InvalidVersion::PSERROR_File_InvalidVersion() : PSERROR_File(NULL) { } PSERROR_File_InvalidVersion::PSERROR_File_InvalidVersion(const char* msg) : PSERROR_File(msg) { } PSRETURN PSERROR_File_InvalidVersion::getCode() const { return 0x05000002; } PSERROR_File_OpenFailed::PSERROR_File_OpenFailed() : PSERROR_File(NULL) { } PSERROR_File_OpenFailed::PSERROR_File_OpenFailed(const char* msg) : PSERROR_File(msg) { } PSRETURN PSERROR_File_OpenFailed::getCode() const { return 0x05000003; } PSERROR_File_ReadFailed::PSERROR_File_ReadFailed() : PSERROR_File(NULL) { } PSERROR_File_ReadFailed::PSERROR_File_ReadFailed(const char* msg) : PSERROR_File(msg) { } PSRETURN PSERROR_File_ReadFailed::getCode() const { return 0x05000004; } PSERROR_File_UnexpectedEOF::PSERROR_File_UnexpectedEOF() : PSERROR_File(NULL) { } PSERROR_File_UnexpectedEOF::PSERROR_File_UnexpectedEOF(const char* msg) : PSERROR_File(msg) { } PSRETURN PSERROR_File_UnexpectedEOF::getCode() const { return 0x05000005; } PSERROR_File_WriteFailed::PSERROR_File_WriteFailed() : PSERROR_File(NULL) { } PSERROR_File_WriteFailed::PSERROR_File_WriteFailed(const char* msg) : PSERROR_File(msg) { } PSRETURN PSERROR_File_WriteFailed::getCode() const { return 0x05000006; } PSERROR_GUI_InvalidSetting::PSERROR_GUI_InvalidSetting() : PSERROR_GUI(NULL) { } PSERROR_GUI_InvalidSetting::PSERROR_GUI_InvalidSetting(const char* msg) : PSERROR_GUI(msg) { } PSRETURN PSERROR_GUI_InvalidSetting::getCode() const { return 0x06000001; } PSERROR_GUI_JSOpenFailed::PSERROR_GUI_JSOpenFailed() : PSERROR_GUI(NULL) { } PSERROR_GUI_JSOpenFailed::PSERROR_GUI_JSOpenFailed(const char* msg) : PSERROR_GUI(msg) { } PSRETURN PSERROR_GUI_JSOpenFailed::getCode() const { return 0x06000002; } PSERROR_GUI_NameAmbiguity::PSERROR_GUI_NameAmbiguity() : PSERROR_GUI(NULL) { } PSERROR_GUI_NameAmbiguity::PSERROR_GUI_NameAmbiguity(const char* msg) : PSERROR_GUI(msg) { } PSRETURN PSERROR_GUI_NameAmbiguity::getCode() const { return 0x06000003; } PSERROR_GUI_ObjectNeedsName::PSERROR_GUI_ObjectNeedsName() : PSERROR_GUI(NULL) { } PSERROR_GUI_ObjectNeedsName::PSERROR_GUI_ObjectNeedsName(const char* msg) : PSERROR_GUI(msg) { } PSRETURN PSERROR_GUI_ObjectNeedsName::getCode() const { return 0x06000004; } PSERROR_GUI_OperationNeedsGUIObject::PSERROR_GUI_OperationNeedsGUIObject() : PSERROR_GUI(NULL) { } PSERROR_GUI_OperationNeedsGUIObject::PSERROR_GUI_OperationNeedsGUIObject(const char* msg) : PSERROR_GUI(msg) { } PSRETURN PSERROR_GUI_OperationNeedsGUIObject::getCode() const { return 0x06000005; } PSERROR_GUI_UnableToParse::PSERROR_GUI_UnableToParse() : PSERROR_GUI(NULL) { } PSERROR_GUI_UnableToParse::PSERROR_GUI_UnableToParse(const char* msg) : PSERROR_GUI(msg) { } PSRETURN PSERROR_GUI_UnableToParse::getCode() const { return 0x06000006; } PSERROR_Game_World_MapLoadFailed::PSERROR_Game_World_MapLoadFailed() : PSERROR_Game_World(NULL) { } PSERROR_Game_World_MapLoadFailed::PSERROR_Game_World_MapLoadFailed(const char* msg) : PSERROR_Game_World(msg) { } PSRETURN PSERROR_Game_World_MapLoadFailed::getCode() const { return 0x07030001; } PSERROR_Scripting_DefineType_AlreadyExists::PSERROR_Scripting_DefineType_AlreadyExists() : PSERROR_Scripting_DefineType(NULL) { } PSERROR_Scripting_DefineType_AlreadyExists::PSERROR_Scripting_DefineType_AlreadyExists(const char* msg) : PSERROR_Scripting_DefineType(msg) { } PSRETURN PSERROR_Scripting_DefineType_AlreadyExists::getCode() const { return 0x08010001; } PSERROR_Scripting_DefineType_CreationFailed::PSERROR_Scripting_DefineType_CreationFailed() : PSERROR_Scripting_DefineType(NULL) { } PSERROR_Scripting_DefineType_CreationFailed::PSERROR_Scripting_DefineType_CreationFailed(const char* msg) : PSERROR_Scripting_DefineType(msg) { } PSRETURN PSERROR_Scripting_DefineType_CreationFailed::getCode() const { return 0x08010002; } PSERROR_Scripting_LoadFile_EvalErrors::PSERROR_Scripting_LoadFile_EvalErrors() : PSERROR_Scripting_LoadFile(NULL) { } PSERROR_Scripting_LoadFile_EvalErrors::PSERROR_Scripting_LoadFile_EvalErrors(const char* msg) : PSERROR_Scripting_LoadFile(msg) { } PSRETURN PSERROR_Scripting_LoadFile_EvalErrors::getCode() const { return 0x08020001; } PSERROR_Scripting_LoadFile_OpenFailed::PSERROR_Scripting_LoadFile_OpenFailed() : PSERROR_Scripting_LoadFile(NULL) { } PSERROR_Scripting_LoadFile_OpenFailed::PSERROR_Scripting_LoadFile_OpenFailed(const char* msg) : PSERROR_Scripting_LoadFile(msg) { } PSRETURN PSERROR_Scripting_LoadFile_OpenFailed::getCode() const { return 0x08020002; } PSERROR_Scripting_CallFunctionFailed::PSERROR_Scripting_CallFunctionFailed() : PSERROR_Scripting(NULL) { } PSERROR_Scripting_CallFunctionFailed::PSERROR_Scripting_CallFunctionFailed(const char* msg) : PSERROR_Scripting(msg) { } PSRETURN PSERROR_Scripting_CallFunctionFailed::getCode() const { return 0x08000001; } -PSERROR_Scripting_ConversionFailed::PSERROR_Scripting_ConversionFailed() : PSERROR_Scripting(NULL) { } -PSERROR_Scripting_ConversionFailed::PSERROR_Scripting_ConversionFailed(const char* msg) : PSERROR_Scripting(msg) { } -PSRETURN PSERROR_Scripting_ConversionFailed::getCode() const { return 0x08000002; } - PSERROR_Scripting_CreateObjectFailed::PSERROR_Scripting_CreateObjectFailed() : PSERROR_Scripting(NULL) { } PSERROR_Scripting_CreateObjectFailed::PSERROR_Scripting_CreateObjectFailed(const char* msg) : PSERROR_Scripting(msg) { } -PSRETURN PSERROR_Scripting_CreateObjectFailed::getCode() const { return 0x08000003; } +PSRETURN PSERROR_Scripting_CreateObjectFailed::getCode() const { return 0x08000002; } PSERROR_Scripting_DefineConstantFailed::PSERROR_Scripting_DefineConstantFailed() : PSERROR_Scripting(NULL) { } PSERROR_Scripting_DefineConstantFailed::PSERROR_Scripting_DefineConstantFailed(const char* msg) : PSERROR_Scripting(msg) { } -PSRETURN PSERROR_Scripting_DefineConstantFailed::getCode() const { return 0x08000004; } +PSRETURN PSERROR_Scripting_DefineConstantFailed::getCode() const { return 0x08000003; } PSERROR_Scripting_RegisterFunctionFailed::PSERROR_Scripting_RegisterFunctionFailed() : PSERROR_Scripting(NULL) { } PSERROR_Scripting_RegisterFunctionFailed::PSERROR_Scripting_RegisterFunctionFailed(const char* msg) : PSERROR_Scripting(msg) { } -PSRETURN PSERROR_Scripting_RegisterFunctionFailed::getCode() const { return 0x08000005; } +PSRETURN PSERROR_Scripting_RegisterFunctionFailed::getCode() const { return 0x08000004; } PSERROR_Scripting_SetupFailed::PSERROR_Scripting_SetupFailed() : PSERROR_Scripting(NULL) { } PSERROR_Scripting_SetupFailed::PSERROR_Scripting_SetupFailed(const char* msg) : PSERROR_Scripting(msg) { } -PSRETURN PSERROR_Scripting_SetupFailed::getCode() const { return 0x08000006; } +PSRETURN PSERROR_Scripting_SetupFailed::getCode() const { return 0x08000005; } PSERROR_Scripting_TypeDoesNotExist::PSERROR_Scripting_TypeDoesNotExist() : PSERROR_Scripting(NULL) { } PSERROR_Scripting_TypeDoesNotExist::PSERROR_Scripting_TypeDoesNotExist(const char* msg) : PSERROR_Scripting(msg) { } -PSRETURN PSERROR_Scripting_TypeDoesNotExist::getCode() const { return 0x08000007; } +PSRETURN PSERROR_Scripting_TypeDoesNotExist::getCode() const { return 0x08000006; } PSERROR_Serialize_InvalidCharInString::PSERROR_Serialize_InvalidCharInString() : PSERROR_Serialize(NULL) { } PSERROR_Serialize_InvalidCharInString::PSERROR_Serialize_InvalidCharInString(const char* msg) : PSERROR_Serialize(msg) { } PSRETURN PSERROR_Serialize_InvalidCharInString::getCode() const { return 0x09000001; } PSERROR_Serialize_InvalidScriptValue::PSERROR_Serialize_InvalidScriptValue() : PSERROR_Serialize(NULL) { } PSERROR_Serialize_InvalidScriptValue::PSERROR_Serialize_InvalidScriptValue(const char* msg) : PSERROR_Serialize(msg) { } PSRETURN PSERROR_Serialize_InvalidScriptValue::getCode() const { return 0x09000002; } PSERROR_Serialize_OutOfBounds::PSERROR_Serialize_OutOfBounds() : PSERROR_Serialize(NULL) { } PSERROR_Serialize_OutOfBounds::PSERROR_Serialize_OutOfBounds(const char* msg) : PSERROR_Serialize(msg) { } PSRETURN PSERROR_Serialize_OutOfBounds::getCode() const { return 0x09000003; } PSERROR_Serialize_ScriptError::PSERROR_Serialize_ScriptError() : PSERROR_Serialize(NULL) { } PSERROR_Serialize_ScriptError::PSERROR_Serialize_ScriptError(const char* msg) : PSERROR_Serialize(msg) { } PSRETURN PSERROR_Serialize_ScriptError::getCode() const { return 0x09000004; } PSERROR_System_RequiredExtensionsMissing::PSERROR_System_RequiredExtensionsMissing() : PSERROR_System(NULL) { } PSERROR_System_RequiredExtensionsMissing::PSERROR_System_RequiredExtensionsMissing(const char* msg) : PSERROR_System(msg) { } PSRETURN PSERROR_System_RequiredExtensionsMissing::getCode() const { return 0x0a000001; } PSERROR_System_SDLInitFailed::PSERROR_System_SDLInitFailed() : PSERROR_System(NULL) { } PSERROR_System_SDLInitFailed::PSERROR_System_SDLInitFailed(const char* msg) : PSERROR_System(msg) { } PSRETURN PSERROR_System_SDLInitFailed::getCode() const { return 0x0a000002; } PSERROR_System_VmodeFailed::PSERROR_System_VmodeFailed() : PSERROR_System(NULL) { } PSERROR_System_VmodeFailed::PSERROR_System_VmodeFailed(const char* msg) : PSERROR_System(msg) { } PSRETURN PSERROR_System_VmodeFailed::getCode() const { return 0x0a000003; } PSERROR_Xeromyces_XMLOpenFailed::PSERROR_Xeromyces_XMLOpenFailed() : PSERROR_Xeromyces(NULL) { } PSERROR_Xeromyces_XMLOpenFailed::PSERROR_Xeromyces_XMLOpenFailed(const char* msg) : PSERROR_Xeromyces(msg) { } PSRETURN PSERROR_Xeromyces_XMLOpenFailed::getCode() const { return 0x0b000001; } PSERROR_Xeromyces_XMLParseError::PSERROR_Xeromyces_XMLParseError() : PSERROR_Xeromyces(NULL) { } PSERROR_Xeromyces_XMLParseError::PSERROR_Xeromyces_XMLParseError(const char* msg) : PSERROR_Xeromyces(msg) { } PSRETURN PSERROR_Xeromyces_XMLParseError::getCode() const { return 0x0b000002; } PSERROR::PSERROR(const char* msg) : m_msg(msg) { } const char* PSERROR::what() const throw () { return m_msg ? m_msg : GetErrorString(getCode()); } const char* GetErrorString(PSRETURN code) { switch (code) { case 0x01000001: return "CVFSFile_AlreadyLoaded"; case 0x01000002: return "CVFSFile_LoadFailed"; case 0x02000001: return "Deserialize_InvalidCharInString"; case 0x02000002: return "Deserialize_OutOfBounds"; case 0x02000003: return "Deserialize_ReadFailed"; case 0x02000004: return "Deserialize_ScriptError"; case 0x03000001: return "DllLoader_DllNotLoaded"; case 0x03000002: return "DllLoader_SymbolNotFound"; case 0x04000001: return "Error_InvalidError"; case 0x05000001: return "File_InvalidType"; case 0x05000002: return "File_InvalidVersion"; case 0x05000003: return "File_OpenFailed"; case 0x05000004: return "File_ReadFailed"; case 0x05000005: return "File_UnexpectedEOF"; case 0x05000006: return "File_WriteFailed"; case 0x06000001: return "GUI_InvalidSetting"; case 0x06000002: return "GUI_JSOpenFailed"; case 0x06000003: return "GUI_NameAmbiguity"; case 0x06000004: return "GUI_ObjectNeedsName"; case 0x06000005: return "GUI_OperationNeedsGUIObject"; case 0x06000006: return "GUI_UnableToParse"; case 0x07030001: return "Game_World_MapLoadFailed"; case 0x08010001: return "Scripting_DefineType_AlreadyExists"; case 0x08010002: return "Scripting_DefineType_CreationFailed"; case 0x08020001: return "Scripting_LoadFile_EvalErrors"; case 0x08020002: return "Scripting_LoadFile_OpenFailed"; case 0x08000001: return "Scripting_CallFunctionFailed"; - case 0x08000002: return "Scripting_ConversionFailed"; - case 0x08000003: return "Scripting_CreateObjectFailed"; - case 0x08000004: return "Scripting_DefineConstantFailed"; - case 0x08000005: return "Scripting_RegisterFunctionFailed"; - case 0x08000006: return "Scripting_SetupFailed"; - case 0x08000007: return "Scripting_TypeDoesNotExist"; + case 0x08000002: return "Scripting_CreateObjectFailed"; + case 0x08000003: return "Scripting_DefineConstantFailed"; + case 0x08000004: return "Scripting_RegisterFunctionFailed"; + case 0x08000005: return "Scripting_SetupFailed"; + case 0x08000006: return "Scripting_TypeDoesNotExist"; case 0x09000001: return "Serialize_InvalidCharInString"; case 0x09000002: return "Serialize_InvalidScriptValue"; case 0x09000003: return "Serialize_OutOfBounds"; case 0x09000004: return "Serialize_ScriptError"; case 0x0a000001: return "System_RequiredExtensionsMissing"; case 0x0a000002: return "System_SDLInitFailed"; case 0x0a000003: return "System_VmodeFailed"; case 0x0b000001: return "Xeromyces_XMLOpenFailed"; case 0x0b000002: return "Xeromyces_XMLParseError"; default: return "Unrecognised error"; } } void ThrowError(PSRETURN code) { switch (code) // Use 'break' in case someone tries to continue from the exception { case 0x01000001: throw PSERROR_CVFSFile_AlreadyLoaded(); break; case 0x01000002: throw PSERROR_CVFSFile_LoadFailed(); break; case 0x02000001: throw PSERROR_Deserialize_InvalidCharInString(); break; case 0x02000002: throw PSERROR_Deserialize_OutOfBounds(); break; case 0x02000003: throw PSERROR_Deserialize_ReadFailed(); break; case 0x02000004: throw PSERROR_Deserialize_ScriptError(); break; case 0x03000001: throw PSERROR_DllLoader_DllNotLoaded(); break; case 0x03000002: throw PSERROR_DllLoader_SymbolNotFound(); break; case 0x04000001: throw PSERROR_Error_InvalidError(); break; case 0x05000001: throw PSERROR_File_InvalidType(); break; case 0x05000002: throw PSERROR_File_InvalidVersion(); break; case 0x05000003: throw PSERROR_File_OpenFailed(); break; case 0x05000004: throw PSERROR_File_ReadFailed(); break; case 0x05000005: throw PSERROR_File_UnexpectedEOF(); break; case 0x05000006: throw PSERROR_File_WriteFailed(); break; case 0x06000001: throw PSERROR_GUI_InvalidSetting(); break; case 0x06000002: throw PSERROR_GUI_JSOpenFailed(); break; case 0x06000003: throw PSERROR_GUI_NameAmbiguity(); break; case 0x06000004: throw PSERROR_GUI_ObjectNeedsName(); break; case 0x06000005: throw PSERROR_GUI_OperationNeedsGUIObject(); break; case 0x06000006: throw PSERROR_GUI_UnableToParse(); break; case 0x07030001: throw PSERROR_Game_World_MapLoadFailed(); break; case 0x08010001: throw PSERROR_Scripting_DefineType_AlreadyExists(); break; case 0x08010002: throw PSERROR_Scripting_DefineType_CreationFailed(); break; case 0x08020001: throw PSERROR_Scripting_LoadFile_EvalErrors(); break; case 0x08020002: throw PSERROR_Scripting_LoadFile_OpenFailed(); break; case 0x08000001: throw PSERROR_Scripting_CallFunctionFailed(); break; - case 0x08000002: throw PSERROR_Scripting_ConversionFailed(); break; - case 0x08000003: throw PSERROR_Scripting_CreateObjectFailed(); break; - case 0x08000004: throw PSERROR_Scripting_DefineConstantFailed(); break; - case 0x08000005: throw PSERROR_Scripting_RegisterFunctionFailed(); break; - case 0x08000006: throw PSERROR_Scripting_SetupFailed(); break; - case 0x08000007: throw PSERROR_Scripting_TypeDoesNotExist(); break; + case 0x08000002: throw PSERROR_Scripting_CreateObjectFailed(); break; + case 0x08000003: throw PSERROR_Scripting_DefineConstantFailed(); break; + case 0x08000004: throw PSERROR_Scripting_RegisterFunctionFailed(); break; + case 0x08000005: throw PSERROR_Scripting_SetupFailed(); break; + case 0x08000006: throw PSERROR_Scripting_TypeDoesNotExist(); break; case 0x09000001: throw PSERROR_Serialize_InvalidCharInString(); break; case 0x09000002: throw PSERROR_Serialize_InvalidScriptValue(); break; case 0x09000003: throw PSERROR_Serialize_OutOfBounds(); break; case 0x09000004: throw PSERROR_Serialize_ScriptError(); break; case 0x0a000001: throw PSERROR_System_RequiredExtensionsMissing(); break; case 0x0a000002: throw PSERROR_System_SDLInitFailed(); break; case 0x0a000003: throw PSERROR_System_VmodeFailed(); break; case 0x0b000001: throw PSERROR_Xeromyces_XMLOpenFailed(); break; case 0x0b000002: throw PSERROR_Xeromyces_XMLParseError(); break; default: throw PSERROR_Error_InvalidError(); // Hmm... } } Index: ps/trunk/source/scriptinterface/ScriptInterface.h =================================================================== --- ps/trunk/source/scriptinterface/ScriptInterface.h (revision 22846) +++ ps/trunk/source/scriptinterface/ScriptInterface.h (revision 22847) @@ -1,620 +1,619 @@ /* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #ifndef INCLUDED_SCRIPTINTERFACE #define INCLUDED_SCRIPTINTERFACE #include "lib/file/vfs/vfs_path.h" #include "maths/Fixed.h" #include "ScriptTypes.h" #include "ps/Errors.h" #include #include ERROR_GROUP(Scripting); ERROR_TYPE(Scripting, SetupFailed); ERROR_SUBGROUP(Scripting, LoadFile); ERROR_TYPE(Scripting_LoadFile, OpenFailed); ERROR_TYPE(Scripting_LoadFile, EvalErrors); -ERROR_TYPE(Scripting, ConversionFailed); ERROR_TYPE(Scripting, CallFunctionFailed); ERROR_TYPE(Scripting, RegisterFunctionFailed); ERROR_TYPE(Scripting, DefineConstantFailed); ERROR_TYPE(Scripting, CreateObjectFailed); ERROR_TYPE(Scripting, TypeDoesNotExist); ERROR_SUBGROUP(Scripting, DefineType); ERROR_TYPE(Scripting_DefineType, AlreadyExists); ERROR_TYPE(Scripting_DefineType, CreationFailed); // Set the maximum number of function arguments that can be handled // (This should be as small as possible (for compiler efficiency), // but as large as necessary for all wrapped functions) #define SCRIPT_INTERFACE_MAX_ARGS 8 // TODO: what's a good default? #define DEFAULT_RUNTIME_SIZE 16 * 1024 * 1024 #define DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER 2 * 1024 *1024 struct ScriptInterface_impl; class ScriptRuntime; extern shared_ptr g_ScriptRuntime; /** * Abstraction around a SpiderMonkey JSContext. * * Thread-safety: * - May be used in non-main threads. * - Each ScriptInterface must be created, used, and destroyed, all in a single thread * (it must never be shared between threads). */ class ScriptInterface { NONCOPYABLE(ScriptInterface); public: /** * Returns a runtime, which can used to initialise any number of * ScriptInterfaces contexts. Values created in one context may be used * in any other context from the same runtime (but not any other runtime). * Each runtime should only ever be used on a single thread. * @param runtimeSize Maximum size in bytes of the new runtime */ static shared_ptr CreateRuntime(shared_ptr parentRuntime = shared_ptr(), int runtimeSize = DEFAULT_RUNTIME_SIZE, int heapGrowthBytesGCTrigger = DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER); /** * Constructor. * @param nativeScopeName Name of global object that functions (via RegisterFunction) will * be placed into, as a scoping mechanism; typically "Engine" * @param debugName Name of this interface for CScriptStats purposes. * @param runtime ScriptRuntime to use when initializing this interface. */ ScriptInterface(const char* nativeScopeName, const char* debugName, const shared_ptr& runtime); ~ScriptInterface(); struct CxPrivate { ScriptInterface* pScriptInterface; // the ScriptInterface object the current context belongs to void* pCBData; // meant to be used as the "this" object for callback functions } m_CxPrivate; void SetCallbackData(void* pCBData); static CxPrivate* GetScriptInterfaceAndCBData(JSContext* cx); JSContext* GetContext() const; JSRuntime* GetJSRuntime() const; shared_ptr GetRuntime() const; /** * Load global scripts that most script contexts need, * located in the /globalscripts directory. VFS must be initialized. */ bool LoadGlobalScripts(); /** * Replace the default JS random number geenrator with a seeded, network-sync'd one. */ bool ReplaceNondeterministicRNG(boost::rand48& rng); /** * Call a constructor function, equivalent to JS "new ctor(arg)". * @param ctor An object that can be used as constructor * @param argv Constructor arguments * @param out The new object; On error an error message gets logged and out is Null (out.isNull() == true). */ void CallConstructor(JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const; JSObject* CreateCustomObject(const std::string & typeName) const; void DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs); /** * Sets the given value to a new plain JS::Object, converts the arguments to JS::Values and sets them as properties. * Can throw an exception. */ template bool CreateObject(JS::MutableHandleValue objectValue, Args const&... args) const { JSContext* cx = GetContext(); JSAutoRequest rq(cx); JS::RootedObject obj(cx); if (!CreateObject_(&obj, args...)) return false; objectValue.setObject(*obj); return true; } /** * Sets the given value to a new JS object or Null Value in case of out-of-memory. */ void CreateArray(JS::MutableHandleValue objectValue, size_t length = 0) const; JS::Value GetGlobalObject() const; /** * Set the named property on the global object. * Optionally makes it {ReadOnly, DontEnum}. We do not allow to make it DontDelete, so that it can be hotloaded * by deleting it and re-creating it, which is done by setting @p replace to true. */ template bool SetGlobal(const char* name, const T& value, bool replace = false, bool constant = true, bool enumerate = true); /** * Set the named property on the given object. * Optionally makes it {ReadOnly, DontDelete, DontEnum}. */ template bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true) const; /** * Set the named property on the given object. * Optionally makes it {ReadOnly, DontDelete, DontEnum}. */ template bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true) const; /** * Set the integer-named property on the given object. * Optionally makes it {ReadOnly, DontDelete, DontEnum}. */ template bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true) const; /** * Get the named property on the given object. */ template bool GetProperty(JS::HandleValue obj, const char* name, T& out) const; /** * Get the named property of the given object. */ bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const; bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleObject out) const; /** * Get the integer-named property on the given object. */ template bool GetPropertyInt(JS::HandleValue obj, int name, T& out) const; /** * Get the named property of the given object. */ bool GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandleValue out) const; /** * Check the named property has been defined on the given object. */ bool HasProperty(JS::HandleValue obj, const char* name) const; bool EnumeratePropertyNamesWithPrefix(JS::HandleValue objVal, const char* prefix, std::vector& out) const; bool SetPrototype(JS::HandleValue obj, JS::HandleValue proto); bool FreezeObject(JS::HandleValue objVal, bool deep) const; bool Eval(const char* code) const; template bool Eval(const CHAR* code, JS::MutableHandleValue out) const; template bool Eval(const CHAR* code, T& out) const; /** * Convert an object to a UTF-8 encoded string, either with JSON * (if pretty == true and there is no JSON error) or with toSource(). * * We have to use a mutable handle because JS_Stringify requires that for unknown reasons. */ std::string ToString(JS::MutableHandleValue obj, bool pretty = false) const; /** * Parse a UTF-8-encoded JSON string. Returns the unmodified value on error * and prints an error message. * @return true on success; false otherwise */ bool ParseJSON(const std::string& string_utf8, JS::MutableHandleValue out) const; /** * Read a JSON file. Returns the unmodified value on error and prints an error message. */ void ReadJSONFile(const VfsPath& path, JS::MutableHandleValue out) const; /** * Stringify to a JSON string, UTF-8 encoded. Returns an empty string on error. */ std::string StringifyJSON(JS::MutableHandleValue obj, bool indent = true) const; /** * Report the given error message through the JS error reporting mechanism, * and throw a JS exception. (Callers can check IsPendingException, and must * return false in that case to propagate the exception.) */ void ReportError(const char* msg) const; /** * Load and execute the given script in a new function scope. * @param filename Name for debugging purposes (not used to load the file) * @param code JS code to execute * @return true on successful compilation and execution; false otherwise */ bool LoadScript(const VfsPath& filename, const std::string& code) const; /** * Load and execute the given script in the global scope. * @param filename Name for debugging purposes (not used to load the file) * @param code JS code to execute * @return true on successful compilation and execution; false otherwise */ bool LoadGlobalScript(const VfsPath& filename, const std::wstring& code) const; /** * Load and execute the given script in the global scope. * @return true on successful compilation and execution; false otherwise */ bool LoadGlobalScriptFile(const VfsPath& path) const; /** * Construct a new value (usable in this ScriptInterface's context) by cloning * a value from a different context. * Complex values (functions, XML, etc) won't be cloned correctly, but basic * types and cyclic references should be fine. */ JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const; /** * Convert a JS::Value to a C++ type. (This might trigger GC.) */ template static bool FromJSVal(JSContext* cx, const JS::HandleValue val, T& ret); /** * Convert a C++ type to a JS::Value. (This might trigger GC. The return * value must be rooted if you don't want it to be collected.) * NOTE: We are passing the JS::Value by reference instead of returning it by value. * The reason is a memory corruption problem that appears to be caused by a bug in Visual Studio. * Details here: http://www.wildfiregames.com/forum/index.php?showtopic=17289&p=285921 */ template static void ToJSVal(JSContext* cx, JS::MutableHandleValue ret, T const& val); /** * Convert a named property of an object to a C++ type. */ template static bool FromJSProperty(JSContext* cx, const JS::HandleValue val, const char* name, T& ret); /** * MathRandom (this function) calls the random number generator assigned to this ScriptInterface instance and * returns the generated number. * Math_random (with underscore, not this function) is a global function, but different random number generators can be * stored per ScriptInterface. It calls MathRandom of the current ScriptInterface instance. */ bool MathRandom(double& nbr); /** * Structured clones are a way to serialize 'simple' JS::Values into a buffer * that can safely be passed between contexts and runtimes and threads. * A StructuredClone can be stored and read multiple times if desired. * We wrap them in shared_ptr so memory management is automatic and * thread-safe. */ class StructuredClone { NONCOPYABLE(StructuredClone); public: StructuredClone(); ~StructuredClone(); u64* m_Data; size_t m_Size; }; shared_ptr WriteStructuredClone(JS::HandleValue v) const; void ReadStructuredClone(const shared_ptr& ptr, JS::MutableHandleValue ret) const; /** * Retrieve the private data field of a JSObject that is an instance of the given JSClass. */ template static T* GetPrivate(JSContext* cx, JS::HandleObject thisobj, JSClass* jsClass) { JSAutoRequest rq(cx); T* value = static_cast(JS_GetInstancePrivate(cx, thisobj, jsClass, nullptr)); if (value == nullptr && !JS_IsExceptionPending(cx)) JS_ReportError(cx, "Private data of the given object is null!"); return value; } /** * Retrieve the private data field of a JS Object that is an instance of the given JSClass. * If an error occurs, GetPrivate will report it with the according stack. */ template static T* GetPrivate(JSContext* cx, JS::CallArgs& callArgs, JSClass* jsClass) { JSAutoRequest rq(cx); if (!callArgs.thisv().isObject()) { JS_ReportError(cx, "Cannot retrieve private JS class data because from a non-object value!"); return nullptr; } JS::RootedObject thisObj(cx, &callArgs.thisv().toObject()); T* value = static_cast(JS_GetInstancePrivate(cx, thisObj, jsClass, &callArgs)); if (value == nullptr && !JS_IsExceptionPending(cx)) JS_ReportError(cx, "Private data of the given object is null!"); return value; } /** * Converts |a| if needed and assigns it to |handle|. * This is meant for use in other templates where we want to use the same code for JS::RootedValue&/JS::HandleValue and * other types. Note that functions are meant to take JS::HandleValue instead of JS::RootedValue&, but this implicit * conversion does not work for templates (exact type matches required for type deduction). * A similar functionality could also be implemented as a ToJSVal specialization. The current approach was preferred * because "conversions" from JS::HandleValue to JS::MutableHandleValue are unusual and should not happen "by accident". */ template static void AssignOrToJSVal(JSContext* cx, JS::MutableHandleValue handle, const T& a); /** * The same as AssignOrToJSVal, but also allows JS::Value for T. * In most cases it's not safe to use the plain (unrooted) JS::Value type, but this can happen quite * easily with template functions. The idea is that the linker prints an error if AssignOrToJSVal is * used with JS::Value. If the specialization for JS::Value should be allowed, you can use this * "unrooted" version of AssignOrToJSVal. */ template static void AssignOrToJSValUnrooted(JSContext* cx, JS::MutableHandleValue handle, const T& a) { AssignOrToJSVal(cx, handle, a); } /** * Converts |val| to T if needed or just returns it if it's a handle. * This is meant for use in other templates where we want to use the same code for JS::HandleValue and * other types. */ template static T AssignOrFromJSVal(JSContext* cx, const JS::HandleValue& val, bool& ret); private: /** * Careful, the CreateObject_ helpers avoid creation of the JSAutoRequest! */ bool CreateObject_(JS::MutableHandleObject obj) const; template bool CreateObject_(JS::MutableHandleObject obj, const char* propertyName, const T& propertyValue, Args const&... args) const { // JSAutoRequest is the responsibility of the caller JSContext* cx = GetContext(); JS::RootedValue val(cx); AssignOrToJSVal(cx, &val, propertyValue); return CreateObject_(obj, args...) && JS_DefineProperty(cx, obj, propertyName, val, JSPROP_ENUMERATE); } bool CallFunction_(JS::HandleValue val, const char* name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const; bool Eval_(const char* code, JS::MutableHandleValue ret) const; bool Eval_(const wchar_t* code, JS::MutableHandleValue ret) const; bool SetGlobal_(const char* name, JS::HandleValue value, bool replace, bool constant, bool enumerate); bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const; bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) const; bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) const; bool GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const; bool GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const; static bool IsExceptionPending(JSContext* cx); struct CustomType { // TODO: Move assignment operator and move constructor only have to be // explicitly defined for Visual Studio. VS2013 is still behind on C++11 support // What's missing is what they call "Rvalue references v3.0", see // https://msdn.microsoft.com/en-us/library/hh567368.aspx#rvref CustomType() {} CustomType& operator=(CustomType&& other) { m_Prototype = std::move(other.m_Prototype); m_Class = std::move(other.m_Class); m_Constructor = std::move(other.m_Constructor); return *this; } CustomType(CustomType&& other) { m_Prototype = std::move(other.m_Prototype); m_Class = std::move(other.m_Class); m_Constructor = std::move(other.m_Constructor); } JS::PersistentRootedObject m_Prototype; JSClass* m_Class; JSNative m_Constructor; }; void Register(const char* name, JSNative fptr, size_t nargs) const; // Take care to keep this declaration before heap rooted members. Destructors of heap rooted // members have to be called before the runtime destructor. std::unique_ptr m; boost::rand48* m_rng; std::map m_CustomObjectTypes; // The nasty macro/template bits are split into a separate file so you don't have to look at them public: #include "NativeWrapperDecls.h" // This declares: // // template // void RegisterFunction(const char* functionName) const; // // template // static JSNative call; // // template // static JSNative callMethod; // // template // static JSNative callMethodConst; // // template // static size_t nargs(); // // template // bool CallFunction(JS::HandleValue val, const char* name, R& ret, const T0&...) const; // // template // bool CallFunction(JS::HandleValue val, const char* name, JS::Rooted* ret, const T0&...) const; // // template // bool CallFunction(JS::HandleValue val, const char* name, JS::MutableHandle ret, const T0&...) const; // // template // bool CallFunctionVoid(JS::HandleValue val, const char* name, const T0&...) const; }; // Implement those declared functions #include "NativeWrapperDefns.h" template inline void ScriptInterface::AssignOrToJSVal(JSContext* cx, JS::MutableHandleValue handle, const T& a) { ToJSVal(cx, handle, a); } template<> inline void ScriptInterface::AssignOrToJSVal(JSContext* UNUSED(cx), JS::MutableHandleValue handle, const JS::PersistentRootedValue& a) { handle.set(a); } template<> inline void ScriptInterface::AssignOrToJSVal(JSContext* UNUSED(cx), JS::MutableHandleValue handle, const JS::RootedValue& a) { handle.set(a); } template <> inline void ScriptInterface::AssignOrToJSVal(JSContext* UNUSED(cx), JS::MutableHandleValue handle, const JS::HandleValue& a) { handle.set(a); } template <> inline void ScriptInterface::AssignOrToJSValUnrooted(JSContext* UNUSED(cx), JS::MutableHandleValue handle, const JS::Value& a) { handle.set(a); } template inline T ScriptInterface::AssignOrFromJSVal(JSContext* cx, const JS::HandleValue& val, bool& ret) { T retVal; ret = FromJSVal(cx, val, retVal); return retVal; } template<> inline JS::HandleValue ScriptInterface::AssignOrFromJSVal(JSContext* UNUSED(cx), const JS::HandleValue& val, bool& ret) { ret = true; return val; } template bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace, bool constant, bool enumerate) { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); AssignOrToJSVal(GetContext(), &val, value); return SetGlobal_(name, val, replace, constant, enumerate); } template bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant, bool enumerate) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); AssignOrToJSVal(GetContext(), &val, value); return SetProperty_(obj, name, val, constant, enumerate); } template bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant, bool enumerate) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); AssignOrToJSVal(GetContext(), &val, value); return SetProperty_(obj, name, val, constant, enumerate); } template bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant, bool enumerate) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); AssignOrToJSVal(GetContext(), &val, value); return SetPropertyInt_(obj, name, val, constant, enumerate); } template bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, T& out) const { JSContext* cx = GetContext(); JSAutoRequest rq(cx); JS::RootedValue val(cx); if (!GetProperty_(obj, name, &val)) return false; return FromJSVal(cx, val, out); } template bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, T& out) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); if (!GetPropertyInt_(obj, name, &val)) return false; return FromJSVal(GetContext(), val, out); } template bool ScriptInterface::Eval(const CHAR* code, JS::MutableHandleValue ret) const { if (!Eval_(code, ret)) return false; return true; } template bool ScriptInterface::Eval(const CHAR* code, T& ret) const { JSAutoRequest rq(GetContext()); JS::RootedValue rval(GetContext()); if (!Eval_(code, &rval)) return false; return FromJSVal(GetContext(), rval, ret); } #endif // INCLUDED_SCRIPTINTERFACE