Ticket #2213: Unify_ScriptConversions_v1.1.diff
File Unify_ScriptConversions_v1.1.diff, 23.5 KB (added by , 11 years ago) |
---|
-
source/scriptinterface/ScriptConversions.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2013 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 100 100 return true; 101 101 } 102 102 103 template<> bool ScriptInterface::FromJSVal<long>(JSContext* cx, jsval v, long& out) 104 { 105 int32 tmp; 106 JSBool ok = JS_ValueToInt32(cx, v, &tmp); 107 out = (long)tmp; 108 return ok == JS_TRUE; 109 } 110 111 template<> bool ScriptInterface::FromJSVal<unsigned long>(JSContext* cx, jsval v, unsigned long& out) 112 { 113 int32 tmp; 114 JSBool ok = JS_ValueToInt32(cx, v, &tmp); 115 out = (unsigned long)tmp; 116 return ok == JS_TRUE; 117 } 118 119 // see comment at declaration of specialization 120 #if !GCC_VERSION 121 #if ARCH_AMD64 122 123 template<> bool ScriptInterface::FromJSVal<size_t>(JSContext* cx, jsval v, size_t& out) 124 { 125 int temp; 126 if(!FromJSVal<int>(cx, v, temp)) 127 return false; 128 if(temp < 0) 129 return false; 130 out = (size_t)temp; 131 return true; 132 } 133 134 template<> bool ScriptInterface::FromJSVal<ssize_t>(JSContext* cx, jsval v, ssize_t& out) 135 { 136 int temp; 137 if(!FromJSVal<int>(cx, v, temp)) 138 return false; 139 if(temp < 0) 140 return false; 141 Storage = (ssize_t)temp; 142 return true; 143 } 144 145 #endif // #if ARCH_AMD64 146 #endif // #if !GCC_VERSION 147 103 148 // NOTE: we can't define a jsval specialisation, because that conflicts with integer types 104 149 template<> bool ScriptInterface::FromJSVal<CScriptVal>(JSContext* UNUSED(cx), jsval v, CScriptVal& out) 105 150 { … … 150 195 return true; 151 196 } 152 197 198 template<> bool ScriptInterface::FromJSVal<CStr8>(JSContext* cx, jsval v, CStr8& out) 199 { 200 LOGWARNING(L"FromJSVal Str8"); 201 return ScriptInterface::FromJSVal(cx, v, static_cast<std::string&>(out)); 202 } 203 204 template<> bool ScriptInterface::FromJSVal<CStrW>(JSContext* cx, jsval v, CStrW& out) 205 { 206 return ScriptInterface::FromJSVal(cx, v, static_cast<std::wstring&>(out)); 207 } 208 153 209 template<> bool ScriptInterface::FromJSVal<Entity>(JSContext* cx, jsval v, Entity& out) 154 210 { 155 211 JSObject* obj; … … 219 275 JS_NewNumberValue(cx, val, &rval); // ignore return value 220 276 return rval; 221 277 } 278 /* 279 template<> jsval ScriptInterface::ToJSVal<unsigned>(JSContext* UNUSED(cx), const unsigned& val) 280 { 281 return INT_TO_JSVAL(val); 282 }*/ 222 283 284 template<> jsval ScriptInterface::ToJSVal<long>(JSContext* UNUSED(cx), const long& val) 285 { 286 return INT_TO_JSVAL((int)val); 287 } 288 289 template<> jsval ScriptInterface::ToJSVal<unsigned long>(JSContext* UNUSED(cx), const unsigned long& val) 290 { 291 return INT_TO_JSVAL((int)val); 292 } 293 294 // (s)size_t are considered to be identical to (unsigned) int by GCC and 295 // their specializations would cause conflicts there. On x86_64 GCC, s/size_t 296 // is equivalent to (unsigned) long, but the same solution applies; use the 297 // long and unsigned long specializations instead of s/size_t. 298 #if !GCC_VERSION 299 300 // for some reason, x64 MSC treats size_t as distinct from unsigned long: 301 #if ARCH_AMD64 302 303 template<> jsval ScriptInterface::ToJSVal<size_t>(JSContext* UNUSED(cx), const size_t& val) 304 { 305 return INT_TO_JSVAL((int)val); 306 } 307 308 template<> jsval ScriptInterface::ToJSVal<ssize_t>(JSContext* UNUSED(cx), const ssize_t& val) 309 { 310 return( INT_TO_JSVAL( (int)val ) ); 311 } 312 313 #endif // #if ARCH_AMD64 314 #endif // #if !GCC_VERSION 315 223 316 // NOTE: we can't define a jsval specialisation, because that conflicts with integer types 224 317 template<> jsval ScriptInterface::ToJSVal<CScriptVal>(JSContext* UNUSED(cx), const CScriptVal& val) 225 318 { -
source/scriptinterface/DebuggingServer.cpp
21 21 #include "ThreadDebugger.h" 22 22 #include "ps/CLogger.h" 23 23 #include "ps/Filesystem.h" 24 #include "scripting/JSConversions.h"25 24 26 25 CDebuggingServer* g_DebuggingServer = NULL; 27 26 -
source/scripting/JSConversions.cpp
1 /* Copyright (C) 2013 Wildfire Games.2 * This file is part of 0 A.D.3 *4 * 0 A.D. is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 2 of the License, or7 * (at your option) any later version.8 *9 * 0 A.D. is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.16 */17 18 #include "precompiled.h"19 20 #include "JSConversions.h"21 #include "graphics/ObjectManager.h"22 #include "maths/scripting/JSInterface_Vector3D.h"23 #include "lib/sysdep/sysdep.h" // isfinite24 #include "scriptinterface/ScriptInterface.h"25 #include <math.h>26 #include <cfloat>27 28 // CVector3D29 30 template<> CVector3D* ToNative<CVector3D>( JSContext* cx, JSObject* obj )31 {32 JSI_Vector3D::Vector3D_Info* v = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( cx, obj, &JSI_Vector3D::JSI_class, NULL );33 return( v ? v->vector : NULL );34 }35 36 template<> JSObject* ToScript<CVector3D>( CVector3D* Native )37 {38 JSObject* Script = JS_NewObject( g_ScriptingHost.GetContext(), &JSI_Vector3D::JSI_class, NULL, NULL );39 JS_SetPrivate( g_ScriptingHost.GetContext(), Script, new JSI_Vector3D::Vector3D_Info( *Native ) );40 return( Script );41 }42 43 template<> jsval ToJSVal<CVector3D>( const CVector3D& Native )44 {45 JSObject* Script = JS_NewObject( g_ScriptingHost.GetContext(), &JSI_Vector3D::JSI_class, NULL, NULL );46 JS_SetPrivate( g_ScriptingHost.GetContext(), Script, new JSI_Vector3D::Vector3D_Info( Native ) );47 return( OBJECT_TO_JSVAL( Script ) );48 }49 50 // int51 52 template<> jsval ToJSVal<int>( const int& Native )53 {54 return( INT_TO_JSVAL( Native ) );55 }56 57 template<> jsval ToJSVal<int>( int& Native )58 {59 return( INT_TO_JSVAL( Native ) );60 }61 62 template<> bool ToPrimitive<int>( JSContext* cx, jsval v, int& Storage )63 {64 JSBool ok = JS_ValueToInt32(cx, v, (int32*)&Storage);65 return ok == JS_TRUE;66 }67 68 // unsigned69 70 template<> jsval ToJSVal<unsigned>( const unsigned& Native )71 {72 return( INT_TO_JSVAL( Native ) );73 }74 75 template<> jsval ToJSVal<unsigned>( unsigned& Native )76 {77 return( INT_TO_JSVAL( Native ) );78 }79 80 template<> bool ToPrimitive<unsigned>( JSContext* cx, jsval v, unsigned& Storage )81 {82 int temp;83 if(!ToPrimitive<int>(cx, v, temp))84 return false;85 if(temp < 0)86 return false;87 Storage = (unsigned)temp;88 return true;89 }90 91 // long92 template<> jsval ToJSVal<long>( const long& Native )93 {94 return( INT_TO_JSVAL( (int)Native ) );95 }96 97 template<> jsval ToJSVal<long>( long& Native )98 {99 return( INT_TO_JSVAL( (int)Native ) );100 }101 102 template<> bool ToPrimitive<long>( JSContext* cx, jsval v, long& Storage )103 {104 int32 tmp;105 JSBool ok = JS_ValueToInt32(cx, v, &tmp);106 Storage = (long)tmp;107 return ok == JS_TRUE;108 }109 110 // unsigned long111 template<> jsval ToJSVal<unsigned long>( const unsigned long& Native )112 {113 return( INT_TO_JSVAL( (int)Native ) );114 }115 116 template<> jsval ToJSVal<unsigned long>( unsigned long& Native )117 {118 return( INT_TO_JSVAL( (int)Native ) );119 }120 121 template<> bool ToPrimitive<unsigned long>( JSContext* cx, jsval v, unsigned long& Storage )122 {123 int32 tmp;124 JSBool ok = JS_ValueToInt32(cx, v, &tmp);125 Storage = (unsigned long)tmp;126 return ok == JS_TRUE;127 }128 129 // see comment at declaration of specialization130 #if !GCC_VERSION131 #if ARCH_AMD64132 133 template<> jsval ToJSVal<size_t>( const size_t& Native )134 {135 return( INT_TO_JSVAL( (int)Native ) );136 }137 138 template<> jsval ToJSVal<size_t>( size_t& Native )139 {140 return( INT_TO_JSVAL( (int)Native ) );141 }142 143 template<> bool ToPrimitive<size_t>( JSContext* cx, jsval v, size_t& Storage )144 {145 int temp;146 if(!ToPrimitive<int>(cx, v, temp))147 return false;148 if(temp < 0)149 return false;150 Storage = (size_t)temp;151 return true;152 }153 154 155 template<> jsval ToJSVal<ssize_t>( const ssize_t& Native )156 {157 return( INT_TO_JSVAL( (int)Native ) );158 }159 160 template<> jsval ToJSVal<ssize_t>( ssize_t& Native )161 {162 return( INT_TO_JSVAL( (int)Native ) );163 }164 165 template<> bool ToPrimitive<ssize_t>( JSContext* cx, jsval v, ssize_t& Storage )166 {167 int temp;168 if(!ToPrimitive<int>(cx, v, temp))169 return false;170 if(temp < 0)171 return false;172 Storage = (ssize_t)temp;173 return true;174 }175 176 #endif // #if ARCH_AMD64177 #endif // #if !GCC_VERSION178 179 // double180 181 template<> jsval ToJSVal<double>( const double& Native )182 {183 jsval val = JSVAL_VOID;184 JS_NewNumberValue( g_ScriptingHost.getContext(), Native, &val );185 return val;186 }187 188 template<> jsval ToJSVal<double>( double& Native )189 {190 jsval val = JSVAL_VOID;191 JS_NewNumberValue( g_ScriptingHost.getContext(), Native, &val );192 return val;193 }194 195 template<> bool ToPrimitive<double>( JSContext* cx, jsval v, double& Storage )196 {197 JSBool ok = JS_ValueToNumber(cx, v, &Storage);198 if (ok == JS_FALSE || !isfinite( Storage ) )199 return false;200 return true;201 }202 203 // float204 205 template<> jsval ToJSVal<float>( const float& Native )206 {207 jsval val = JSVAL_VOID;208 JS_NewNumberValue( g_ScriptingHost.getContext(), Native, &val );209 return val;210 }211 212 template<> jsval ToJSVal<float>( float& Native )213 {214 jsval val = JSVAL_VOID;215 JS_NewNumberValue( g_ScriptingHost.getContext(), Native, &val );216 return val;217 }218 219 template<> bool ToPrimitive<float>( JSContext* cx, jsval v, float& Storage )220 {221 double temp;222 if(!ToPrimitive<double>(cx, v, temp))223 return false;224 Storage = (float)temp;225 return true;226 }227 228 229 // bool230 231 template<> jsval ToJSVal<bool>( const bool& Native )232 {233 return( BOOLEAN_TO_JSVAL( Native ) );234 }235 236 template<> jsval ToJSVal<bool>( bool& Native )237 {238 return( BOOLEAN_TO_JSVAL( Native ) );239 }240 241 template<> bool ToPrimitive<bool>( JSContext* cx, jsval v, bool& Storage )242 {243 JSBool temp;244 JSBool ok = JS_ValueToBoolean(cx, v, &temp);245 if(ok == JS_FALSE)246 return false;247 Storage = (temp == JS_TRUE);248 return true;249 }250 251 // CStrW252 template<> bool ToPrimitive<CStrW>( JSContext* UNUSED(cx), jsval v, CStrW& Storage )253 {254 try255 {256 Storage = g_ScriptingHost.ValueToUCString( v );257 }258 catch( PSERROR_Scripting_ConversionFailed& )259 {260 return( false );261 }262 return( true );263 }264 265 template<> jsval ToJSVal<CStrW>( const CStrW& Native )266 {267 return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.GetContext(), reinterpret_cast<const jschar*>(Native.utf16().c_str()) ) ) );268 }269 270 template<> jsval ToJSVal<CStrW>( CStrW& Native )271 {272 return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.GetContext(), reinterpret_cast<const jschar*>(Native.utf16().c_str()) ) ) );273 }274 275 // CStr/CStr8276 277 template<> bool ToPrimitive<CStr8>( JSContext* cx, jsval v, CStr8& Storage )278 {279 std::string str;280 if (!ScriptInterface::FromJSVal(cx, v, str))281 return false;282 Storage = str;283 return true;284 }285 286 template<> jsval ToJSVal<CStr8>( const CStr8& Native )287 {288 return( STRING_TO_JSVAL( JS_NewStringCopyZ( g_ScriptingHost.GetContext(), Native.c_str() ) ) );289 }290 291 template<> jsval ToJSVal<CStr8>( CStr8& Native )292 {293 return( STRING_TO_JSVAL( JS_NewStringCopyZ( g_ScriptingHost.GetContext(), Native.c_str() ) ) );294 } -
source/scripting/JSConversions.h
1 /* Copyright (C) 2009 Wildfire Games.2 * This file is part of 0 A.D.3 *4 * 0 A.D. is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 2 of the License, or7 * (at your option) any later version.8 *9 * 0 A.D. is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.16 */17 18 // A general system of converting between native objects and their JavaScript representations19 20 #ifndef INCLUDED_JSCONVERSIONS21 #define INCLUDED_JSCONVERSIONS22 23 #include "scripting/ScriptingHost.h"24 25 class CStrW;26 class CScriptObject;27 class CObjectEntry;28 class CVector3D;29 30 // -----31 //32 // Defaults33 //34 // -----35 36 template<typename T> T* ToNative( JSContext* cx, JSObject* obj )37 {38 return( (T*)JS_GetInstancePrivate( cx, obj, &T::JSI_class, NULL ) );39 }40 41 template<typename T> JSObject* ToScript( T* Native )42 {43 if( !Native )44 return( (JSObject*)NULL );45 return( Native->GetScript() );46 }47 48 template<typename T> T* ToNative( jsval v )49 {50 if( !JSVAL_IS_OBJECT( v ) ) return( NULL );51 if( v == JSVAL_NULL ) return( NULL );52 return( ToNative<T>( g_ScriptingHost.GetContext(), JSVAL_TO_OBJECT( v ) ) );53 }54 55 template<typename T> bool ToPrimitive( JSContext* UNUSED(cx), jsval v, T& Storage )56 {57 T* Native = ToNative<T>( v );58 if( !Native ) return( false );59 Storage = *Native;60 return( true );61 }62 63 // Handle pointer-to-objects sensibly (by automatically dereferencing them one level)64 template<typename T> bool ToPrimitive( JSContext* UNUSED(cx), jsval v, T*& Storage )65 {66 T* Native = ToNative<T>( v );67 if( !Native ) return( false );68 Storage = Native;69 return( true );70 }71 72 // Throws PSERROR_Scripting_ConversionFailed on failure.73 template<typename T> inline T ToPrimitive( JSContext* cx, jsval v )74 {75 T Temp;76 bool ok = ToPrimitive( cx, v, Temp );77 if( !ok ) throw PSERROR_Scripting_ConversionFailed();78 return( Temp );79 }80 81 // Throws PSERROR_Scripting_ConversionFailed on failure.82 template<typename T> inline T ToPrimitive( jsval v )83 {84 return( ToPrimitive<T>( g_ScriptingHost.GetContext(), v ) );85 }86 87 template<typename T> jsval ToJSVal( T& Native )88 {89 return( OBJECT_TO_JSVAL( ToScript<T>( &Native ) ) );90 }91 92 template<typename T> jsval ToJSVal( T*& Native )93 {94 return( OBJECT_TO_JSVAL( ToScript<T>( Native ) ) );95 }96 97 template<typename T> jsval ToJSVal( const T& Native );98 99 // -----100 //101 // Overrides102 //103 // -----104 105 // CVector3D106 template<> CVector3D* ToNative<CVector3D>( JSContext* cx, JSObject* obj );107 template<> JSObject* ToScript<CVector3D>( CVector3D* Native );108 template<> jsval ToJSVal<CVector3D>( const CVector3D& Native );109 110 // CObjectEntry111 template<> bool ToPrimitive<CObjectEntry>( JSContext* cx, jsval v, CObjectEntry*& Storage );112 template<> jsval ToJSVal<CObjectEntry>( CObjectEntry*& Native );113 114 // CScriptObject115 template<> bool ToPrimitive<CScriptObject>( JSContext* cx, jsval v, CScriptObject& Storage );116 template<> jsval ToJSVal<CScriptObject>( CScriptObject& Native );117 118 // int119 template<> bool ToPrimitive<int>( JSContext* cx, jsval v, int& Storage );120 template<> jsval ToJSVal<int>( const int& Native );121 template<> jsval ToJSVal<int>( int& Native );122 123 // unsigned124 template<> bool ToPrimitive<unsigned>( JSContext* cx, jsval v, unsigned& Storage );125 template<> jsval ToJSVal<unsigned>( const unsigned& Native );126 template<> jsval ToJSVal<unsigned>( unsigned& Native );127 128 // long int129 template<> bool ToPrimitive<long>( JSContext* cx, jsval v, long& Storage );130 template<> jsval ToJSVal<long>( const long& Native );131 template<> jsval ToJSVal<long>( long& Native );132 133 // unsigned long int134 template<> bool ToPrimitive<unsigned long>( JSContext* cx, jsval v, unsigned long& Storage );135 template<> jsval ToJSVal<unsigned long>( const unsigned long& Native );136 template<> jsval ToJSVal<unsigned long>( unsigned long& Native );137 138 // (s)size_t are considered to be identical to (unsigned) int by GCC and139 // their specializations would cause conflicts there. On x86_64 GCC, s/size_t140 // is equivalent to (unsigned) long, but the same solution applies; use the141 // long and unsigned long specializations instead of s/size_t.142 #if !GCC_VERSION143 144 // for some reason, x64 MSC treats size_t as distinct from unsigned long:145 #if ARCH_AMD64146 147 // size_t148 template<> bool ToPrimitive<size_t>( JSContext* cx, jsval v, size_t& Storage );149 template<> jsval ToJSVal<size_t>( const size_t& Native );150 template<> jsval ToJSVal<size_t>( size_t& Native );151 152 // ssize_t153 template<> bool ToPrimitive<ssize_t>( JSContext* cx, jsval v, ssize_t& Storage );154 template<> jsval ToJSVal<ssize_t>( const ssize_t& Native );155 template<> jsval ToJSVal<ssize_t>( ssize_t& Native );156 157 #endif158 159 #endif160 161 // double162 template<> bool ToPrimitive<double>( JSContext* cx, jsval v, double& Storage );163 template<> jsval ToJSVal<double>( const double& Native );164 template<> jsval ToJSVal<double>( double& Native );165 166 // float167 template<> bool ToPrimitive<float>( JSContext* cx, jsval v, float& Storage );168 template<> jsval ToJSVal<float>( const float& Native );169 template<> jsval ToJSVal<float>( float& Native );170 171 // bool172 template<> bool ToPrimitive<bool>( JSContext* cx, jsval v, bool& Storage );173 template<> jsval ToJSVal<bool>( const bool& Native );174 template<> jsval ToJSVal<bool>( bool& Native );175 176 /*177 // char*178 template<> bool ToPrimitive<char*>( JSContext* cx, jsval v, char*& Storage );179 template<> jsval ToJSVal<char*>( const char* Native );180 template<> jsval ToJSVal<char*>( char* Native );181 */182 183 // CStrW184 template<> bool ToPrimitive<CStrW>( JSContext* cx, jsval v, CStrW& Storage );185 template<> jsval ToJSVal<CStrW>( const CStrW& Native );186 template<> jsval ToJSVal<CStrW>( CStrW& Native );187 188 // CStr(8)189 template<> bool ToPrimitive<CStr8>( JSContext* cx, jsval v, CStr8& Storage );190 template<> jsval ToJSVal<CStr8>( const CStr8& Native );191 template<> jsval ToJSVal<CStr8>( CStr8& Native );192 193 #endif -
source/scripting/ScriptGlue.cpp
24 24 #include "precompiled.h" 25 25 26 26 #include "ScriptGlue.h" 27 #include "JSConversions.h"28 27 29 28 #include "graphics/GameView.h" 30 29 #include "graphics/LightEnv.h" … … 37 36 #include "lib/svn_revision.h" 38 37 #include "lib/timer.h" 39 38 #include "lib/sysdep/sysdep.h" // sys_OpenFile 40 #include "maths/scripting/JSInterface_Vector3D.h"41 39 #include "network/NetServer.h" 42 40 #include "ps/CConsole.h" 43 41 #include "ps/CLogger.h" … … 111 109 ONCE(InitJsTimers()); 112 110 113 111 JSU_REQUIRE_PARAMS(1); 114 size_t slot = ToPrimitive<size_t>(JS_ARGV(cx, vp)[0]); 112 size_t slot; 113 ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], slot); 115 114 if (slot >= MAX_JS_TIMERS) 116 115 return JS_FALSE; 117 116 … … 125 124 JSBool StopJsTimer(JSContext* cx, uintN argc, jsval* vp) 126 125 { 127 126 JSU_REQUIRE_PARAMS(1); 128 size_t slot = ToPrimitive<size_t>(JS_ARGV(cx, vp)[0]); 127 size_t slot; 128 ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], slot); 129 129 if (slot >= MAX_JS_TIMERS) 130 130 return JS_FALSE; 131 131 … … 215 215 216 216 try 217 217 { 218 CStr name = ToPrimitive<CStr>(cx, JS_ARGV(cx, vp)[0]); 218 CStr name; 219 ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], name); 219 220 IGUIObject* guiObj = g_GUI->FindObjectByName(name); 220 221 if (guiObj) 221 222 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(guiObj->GetJSObject())); … … 340 341 341 342 try 342 343 { 343 g_Game->m_Paused = ToPrimitive<bool> (JS_ARGV(cx, vp)[0]);344 ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], g_Game->m_Paused); 344 345 345 346 if ( g_SoundManager ) 346 347 g_SoundManager->Pause(g_Game->m_Paused); -
source/ps/scripting/JSInterface_VFS.cpp
23 23 #include "ps/Filesystem.h" 24 24 //#include "lib/res/file/archive/vfs_optimizer.h" // ArchiveBuilderCancel 25 25 #include "scripting/ScriptingHost.h" 26 #include "scriptin g/JSConversions.h"26 #include "scriptinterface/ScriptInterface.h" 27 27 #include "ps/scripting/JSInterface_VFS.h" 28 28 #include "lib/file/vfs/vfs_util.h" 29 29 … … 70 70 { 71 71 BuildDirEntListState* s = (BuildDirEntListState*)cbData; 72 72 73 jsval val = ToJSVal( CStrW(pathname.string()));73 jsval val = ScriptInterface::ToJSVal(s->cx, CStrW(pathname.string())); 74 74 JS_SetElement(s->cx, s->filename_array, s->cur_idx++, &val); 75 75 return INFO::OK; 76 76 } … … 95 95 JSU_REQUIRE_MIN_PARAMS(1); 96 96 97 97 CStrW path; 98 if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], path))98 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], path)) 99 99 return JS_FALSE; 100 100 101 101 CStrW filter_str = L""; 102 102 if (argc >= 2) 103 103 { 104 if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[1], filter_str))104 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[1], filter_str)) 105 105 return JS_FALSE; 106 106 } 107 107 // convert to const wchar_t*; if there's no filter, pass 0 for speed … … 113 113 bool recursive = false; 114 114 if (argc >= 3) 115 115 { 116 if (! ToPrimitive<bool>(cx, JS_ARGV(cx, vp)[2], recursive))116 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[2], recursive)) 117 117 return JS_FALSE; 118 118 } 119 119 int flags = recursive ? vfs::DIR_RECURSIVE : 0; … … 137 137 JSU_REQUIRE_MIN_PARAMS(1); 138 138 139 139 CStrW filename; 140 if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))140 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], filename)) 141 141 return JS_FALSE; 142 142 143 143 CFileInfo fileInfo; 144 144 Status err = g_VFS->GetFileInfo(filename, &fileInfo); 145 145 JS_CHECK_FILE_ERR(err); 146 146 147 JS_SET_RVAL(cx, vp, ToJSVal((double)fileInfo.MTime()));147 JS_SET_RVAL(cx, vp, ScriptInterface::ToJSVal(cx, (double)fileInfo.MTime())); 148 148 return JS_TRUE; 149 149 } 150 150 … … 158 158 JSU_REQUIRE_MIN_PARAMS(1); 159 159 160 160 CStrW filename; 161 if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))161 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], filename)) 162 162 return JS_FALSE; 163 163 164 164 CFileInfo fileInfo; 165 165 Status err = g_VFS->GetFileInfo(filename, &fileInfo); 166 166 JS_CHECK_FILE_ERR(err); 167 167 168 JS_SET_RVAL(cx, vp, ToJSVal( (unsigned)fileInfo.Size()));168 JS_SET_RVAL(cx, vp, ScriptInterface::ToJSVal(cx, (unsigned)fileInfo.Size())); 169 169 return JS_TRUE; 170 170 } 171 171 … … 179 179 JSU_REQUIRE_MIN_PARAMS(1); 180 180 181 181 CStrW filename; 182 if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))182 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], filename)) 183 183 return JS_FALSE; 184 184 185 185 // … … 198 198 contents.Replace("\r\n", "\n"); 199 199 200 200 // Decode as UTF-8 201 JS_SET_RVAL(cx, vp, ToJSVal( contents.FromUTF8()));201 JS_SET_RVAL(cx, vp, ScriptInterface::ToJSVal(cx, contents.FromUTF8())); 202 202 return JS_TRUE; 203 203 } 204 204 … … 212 212 JSU_REQUIRE_MIN_PARAMS(1); 213 213 214 214 CStrW filename; 215 if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))215 if (!ScriptInterface::FromJSVal(cx, JS_ARGV(cx, vp)[0], filename)) 216 216 return (JS_FALSE); 217 217 218 218 // … … 243 243 while (std::getline(ss, line)) 244 244 { 245 245 // Decode each line as UTF-8 246 jsval val = ToJSVal(CStr(line).FromUTF8());246 jsval val = ScriptInterface::ToJSVal(cx, CStr(line).FromUTF8()); 247 247 JS_SetElement(cx, line_array, cur_line++, &val); 248 248 } 249 249 -
source/ps/GameSetup/GameSetup.cpp
48 48 #include "gui/scripting/JSInterface_GUITypes.h" 49 49 #include "gui/scripting/ScriptFunctions.h" 50 50 #include "maths/MathUtil.h" 51 #include "maths/scripting/JSInterface_Vector3D.h"52 51 #include "network/NetServer.h" 53 52 #include "network/NetClient.h" 54 53 … … 318 317 319 318 static void RegisterJavascriptInterfaces() 320 319 { 321 // maths322 JSI_Vector3D::init();323 324 320 // GUI 325 321 CGUI::ScriptingInit(); 326 322