Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ScriptInterface Class Reference

Abstraction around a SpiderMonkey JSContext. More...

#include <ScriptInterface.h>

Classes

class  StructuredClone
 Structured clones are a way to serialize 'simple' JS values into a buffer that can safely be passed between contexts and runtimes and threads. More...
 

Public Member Functions

 ScriptInterface (const char *nativeScopeName, const char *debugName, const shared_ptr< ScriptRuntime > &runtime)
 Constructor. More...
 
 ~ScriptInterface ()
 
void SetCallbackData (void *cbdata)
 
JSContext * GetContext () const
 
JSRuntime * GetRuntime () const
 
bool LoadGlobalScripts ()
 Load global scripts that most script contexts need, located in the /globalscripts directory. More...
 
bool ReplaceNondeterministicRNG (boost::rand48 &rng)
 Replace the default JS random number geenrator with a seeded, network-sync'd one. More...
 
jsval CallConstructor (jsval ctor, jsval arg)
 Call a constructor function, equivalent to JS "new ctor(arg)". More...
 
jsval NewObjectFromConstructor (jsval ctor)
 Create an object as with CallConstructor except don't actually execute the constructor function. More...
 
bool CallFunctionVoid (jsval val, const char *name)
 Call the named property on the given object, with void return type and 0 arguments. More...
 
template<typename T0 >
bool CallFunctionVoid (jsval val, const char *name, const T0 &a0)
 Call the named property on the given object, with void return type and 1 argument. More...
 
template<typename T0 , typename T1 >
bool CallFunctionVoid (jsval val, const char *name, const T0 &a0, const T1 &a1)
 Call the named property on the given object, with void return type and 2 arguments. More...
 
template<typename T0 , typename T1 , typename T2 >
bool CallFunctionVoid (jsval val, const char *name, const T0 &a0, const T1 &a1, const T2 &a2)
 Call the named property on the given object, with void return type and 3 arguments. More...
 
template<typename R >
bool CallFunction (jsval val, const char *name, R &ret)
 Call the named property on the given object, with return type R and 0 arguments. More...
 
template<typename T0 , typename R >
bool CallFunction (jsval val, const char *name, const T0 &a0, R &ret)
 Call the named property on the given object, with return type R and 1 argument. More...
 
template<typename T0 , typename T1 , typename R >
bool CallFunction (jsval val, const char *name, const T0 &a0, const T1 &a1, R &ret)
 Call the named property on the given object, with return type R and 2 arguments. More...
 
template<typename T0 , typename T1 , typename T2 , typename R >
bool CallFunction (jsval val, const char *name, const T0 &a0, const T1 &a1, const T2 &a2, R &ret)
 Call the named property on the given object, with return type R and 3 arguments. More...
 
template<typename T0 , typename T1 , typename T2 , typename T3 , typename R >
bool CallFunction (jsval val, const char *name, const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, R &ret)
 Call the named property on the given object, with return type R and 4 arguments. More...
 
jsval GetGlobalObject ()
 
JSClass * GetGlobalClass ()
 
template<typename T >
bool SetGlobal (const char *name, const T &value, bool replace=false)
 Set the named property on the global object. More...
 
template<typename T >
bool SetProperty (jsval obj, const char *name, const T &value, bool constant=false, bool enumerate=true)
 Set the named property on the given object. More...
 
template<typename T >
bool SetPropertyInt (jsval obj, int name, const T &value, bool constant=false, bool enumerate=true)
 Set the integer-named property on the given object. More...
 
template<typename T >
bool GetProperty (jsval obj, const char *name, T &out)
 Get the named property on the given object. More...
 
template<typename T >
bool GetPropertyInt (jsval obj, int name, T &out)
 Get the integer-named property on the given object. More...
 
bool HasProperty (jsval obj, const char *name)
 Check the named property has been defined on the given object. More...
 
bool EnumeratePropertyNamesWithPrefix (jsval obj, const char *prefix, std::vector< std::string > &out)
 
bool SetPrototype (jsval obj, jsval proto)
 
bool FreezeObject (jsval obj, bool deep)
 
bool Eval (const char *code)
 
template<typename T , typename CHAR >
bool Eval (const CHAR *code, T &out)
 
std::wstring ToString (jsval obj, bool pretty=false)
 
CScriptValRooted ParseJSON (const std::string &string_utf8)
 Parse a UTF-8-encoded JSON string. More...
 
CScriptValRooted ReadJSONFile (const VfsPath &path)
 Read a JSON file. More...
 
std::string StringifyJSON (jsval obj, bool indent=true)
 Stringify to a JSON string, UTF-8 encoded. More...
 
void ReportError (const char *msg)
 Report the given error message through the JS error reporting mechanism, and throw a JS exception. More...
 
bool LoadScript (const VfsPath &filename, const std::string &code)
 Load and execute the given script in a new function scope. More...
 
bool LoadGlobalScript (const VfsPath &filename, const std::string &code)
 Load and execute the given script in the global scope. More...
 
bool LoadGlobalScriptFile (const VfsPath &path)
 Load and execute the given script in the global scope. More...
 
jsval CloneValueFromOtherContext (ScriptInterface &otherContext, jsval val)
 Construct a new value (usable in this ScriptInterface's context) by cloning a value from a different context. More...
 
AutoGCRooterReplaceAutoGCRooter (AutoGCRooter *rooter)
 
void DumpHeap ()
 Dump some memory heap debugging information to stderr. More...
 
void MaybeGC ()
 MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to be worth the amount of time it would take. More...
 
shared_ptr< StructuredCloneWriteStructuredClone (jsval v)
 
jsval ReadStructuredClone (const shared_ptr< StructuredClone > &ptr)
 
template<>
jsval ToJSVal (JSContext *cx, SDL_Event_ const &val)
 
template<>
jsval ToJSVal (JSContext *cx, IGUIObject *const &val)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, bool &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, float &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, double &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, i32 &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, u32 &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, u16 &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, u8 &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, CScriptVal &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, CScriptValRooted &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, Path &out)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, Entity &out)
 
template<>
jsval ToJSVal (JSContext *cx, const bool &val)
 
template<>
jsval ToJSVal (JSContext *cx, const float &val)
 
template<>
jsval ToJSVal (JSContext *cx, const double &val)
 
template<>
jsval ToJSVal (JSContext *cx, const i32 &val)
 
template<>
jsval ToJSVal (JSContext *cx, const u16 &val)
 
template<>
jsval ToJSVal (JSContext *cx, const u8 &val)
 
template<>
jsval ToJSVal (JSContext *cx, const u32 &val)
 
template<>
jsval ToJSVal (JSContext *cx, const CScriptVal &val)
 
template<>
jsval ToJSVal (JSContext *cx, const CScriptValRooted &val)
 
template<>
jsval ToJSVal (JSContext *cx, const Path &val)
 
template<>
jsval ToJSVal (JSContext *cx, const wchar_t *const &val)
 
template<>
jsval ToJSVal (JSContext *cx, const char *const &val)
 
template<>
jsval ToJSVal (JSContext *cx, const CStrW &val)
 
template<>
jsval ToJSVal (JSContext *cx, const CStr8 &val)
 
template<>
jsval ToJSVal (JSContext *cx, IComponent *const &val)
 
template<>
jsval ToJSVal (JSContext *cx, CParamNode const &val)
 
template<>
jsval ToJSVal (JSContext *cx, const CParamNode *const &val)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, CColor &out)
 
template<>
jsval ToJSVal (JSContext *cx, CColor const &val)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, fixed &out)
 
template<>
jsval ToJSVal (JSContext *cx, const fixed &val)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, CFixedVector3D &out)
 
template<>
jsval ToJSVal (JSContext *cx, const CFixedVector3D &val)
 
template<>
bool FromJSVal (JSContext *cx, jsval v, CFixedVector2D &out)
 
template<>
jsval ToJSVal (JSContext *cx, const CFixedVector2D &val)
 
template<>
jsval ToJSVal (JSContext *cx, const Grid< u8 > &val)
 
template<>
jsval ToJSVal (JSContext *cx, const Grid< u16 > &val)
 

Static Public Member Functions

static shared_ptr< ScriptRuntimeCreateRuntime (int runtimeSize=DEFAULT_RUNTIME_SIZE)
 Returns a runtime, which can used to initialise any number of ScriptInterfaces contexts. More...
 
static void ShutDown ()
 Shut down the JS system to clean up memory. More...
 
static void * GetCallbackData (JSContext *cx)
 
template<typename T >
static bool FromJSVal (JSContext *cx, jsval val, T &ret)
 Convert a jsval to a C++ type. More...
 
template<typename T >
static jsval ToJSVal (JSContext *cx, T const &val)
 Convert a C++ type to a jsval. More...
 

Private Member Functions

bool CallFunction_ (jsval val, const char *name, size_t argc, jsval *argv, jsval &ret)
 
bool Eval_ (const char *code, jsval &ret)
 
bool Eval_ (const wchar_t *code, jsval &ret)
 
bool SetGlobal_ (const char *name, jsval value, bool replace)
 
bool SetProperty_ (jsval obj, const char *name, jsval value, bool readonly, bool enumerate)
 
bool SetPropertyInt_ (jsval obj, int name, jsval value, bool readonly, bool enumerate)
 
bool GetProperty_ (jsval obj, const char *name, jsval &value)
 
bool GetPropertyInt_ (jsval obj, int name, jsval &value)
 
void Register (const char *name, JSNative fptr, size_t nargs)
 

Static Private Member Functions

static bool IsExceptionPending (JSContext *cx)
 
static JSClass * GetClass (JSContext *cx, JSObject *obj)
 
static void * GetPrivate (JSContext *cx, JSObject *obj)
 

Private Attributes

std::auto_ptr
< ScriptInterface_impl
m
 

Detailed Description

Abstraction around a SpiderMonkey JSContext.

Thread-safety:

Definition at line 60 of file ScriptInterface.h.

Constructor & Destructor Documentation

ScriptInterface::ScriptInterface ( const char *  nativeScopeName,
const char *  debugName,
const shared_ptr< ScriptRuntime > &  runtime 
)

Constructor.

Parameters
nativeScopeNameName of global object that functions (via RegisterFunction) will be placed into, as a scoping mechanism; typically "Engine"
debugNameName of this interface for CScriptStats purposes.
runtimeScriptRuntime to use when initializing this interface.

Definition at line 580 of file ScriptInterface.cpp.

ScriptInterface::~ScriptInterface ( )

Definition at line 599 of file ScriptInterface.cpp.

Member Function Documentation

jsval ScriptInterface::CallConstructor ( jsval  ctor,
jsval  arg 
)

Call a constructor function, equivalent to JS "new ctor(arg)".

Returns
The new object; or JSVAL_VOID on failure, and logs an error message

Definition at line 690 of file ScriptInterface.cpp.

template<typename R >
bool ScriptInterface::CallFunction ( jsval  val,
const char *  name,
R &  ret 
)

Call the named property on the given object, with return type R and 0 arguments.

Definition at line 362 of file ScriptInterface.h.

template<typename T0 , typename R >
bool ScriptInterface::CallFunction ( jsval  val,
const char *  name,
const T0 a0,
R &  ret 
)

Call the named property on the given object, with return type R and 1 argument.

Definition at line 402 of file ScriptInterface.h.

template<typename T0 , typename T1 , typename R >
bool ScriptInterface::CallFunction ( jsval  val,
const char *  name,
const T0 a0,
const T1 &  a1,
R &  ret 
)

Call the named property on the given object, with return type R and 2 arguments.

Definition at line 414 of file ScriptInterface.h.

template<typename T0 , typename T1 , typename T2 , typename R >
bool ScriptInterface::CallFunction ( jsval  val,
const char *  name,
const T0 a0,
const T1 &  a1,
const T2 &  a2,
R &  ret 
)

Call the named property on the given object, with return type R and 3 arguments.

Definition at line 427 of file ScriptInterface.h.

template<typename T0 , typename T1 , typename T2 , typename T3 , typename R >
bool ScriptInterface::CallFunction ( jsval  val,
const char *  name,
const T0 a0,
const T1 &  a1,
const T2 &  a2,
const T3 &  a3,
R &  ret 
)

Call the named property on the given object, with return type R and 4 arguments.

Definition at line 441 of file ScriptInterface.h.

bool ScriptInterface::CallFunction_ ( jsval  val,
const char *  name,
size_t  argc,
jsval *  argv,
jsval &  ret 
)
private

Definition at line 743 of file ScriptInterface.cpp.

bool ScriptInterface::CallFunctionVoid ( jsval  val,
const char *  name 
)

Call the named property on the given object, with void return type and 0 arguments.

Definition at line 737 of file ScriptInterface.cpp.

template<typename T0 >
bool ScriptInterface::CallFunctionVoid ( jsval  val,
const char *  name,
const T0 a0 
)

Call the named property on the given object, with void return type and 1 argument.

Definition at line 372 of file ScriptInterface.h.

template<typename T0 , typename T1 >
bool ScriptInterface::CallFunctionVoid ( jsval  val,
const char *  name,
const T0 a0,
const T1 &  a1 
)

Call the named property on the given object, with void return type and 2 arguments.

Definition at line 381 of file ScriptInterface.h.

template<typename T0 , typename T1 , typename T2 >
bool ScriptInterface::CallFunctionVoid ( jsval  val,
const char *  name,
const T0 a0,
const T1 &  a1,
const T2 &  a2 
)

Call the named property on the given object, with void return type and 3 arguments.

Definition at line 391 of file ScriptInterface.h.

jsval ScriptInterface::CloneValueFromOtherContext ( ScriptInterface otherContext,
jsval  val 
)

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.

Definition at line 1298 of file ScriptInterface.cpp.

shared_ptr< ScriptRuntime > ScriptInterface::CreateRuntime ( int  runtimeSize = DEFAULT_RUNTIME_SIZE)
static

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.

Parameters
runtimeSizeMaximum size in bytes of the new runtime

Definition at line 227 of file ScriptInterface.cpp.

void ScriptInterface::DumpHeap ( )

Dump some memory heap debugging information to stderr.

Definition at line 1167 of file ScriptInterface.cpp.

bool ScriptInterface::EnumeratePropertyNamesWithPrefix ( jsval  obj,
const char *  prefix,
std::vector< std::string > &  out 
)

Definition at line 857 of file ScriptInterface.cpp.

bool ScriptInterface::Eval ( const char *  code)

Definition at line 987 of file ScriptInterface.cpp.

template<typename T , typename CHAR >
bool ScriptInterface::Eval ( const CHAR code,
T out 
)

Definition at line 492 of file ScriptInterface.h.

bool ScriptInterface::Eval_ ( const char *  code,
jsval &  ret 
)
private

Definition at line 993 of file ScriptInterface.cpp.

bool ScriptInterface::Eval_ ( const wchar_t code,
jsval &  ret 
)
private

Definition at line 1001 of file ScriptInterface.cpp.

bool ScriptInterface::FreezeObject ( jsval  obj,
bool  deep 
)

Definition at line 904 of file ScriptInterface.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
bool &  out 
)

Definition at line 33 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
float &  out 
)

Definition at line 43 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
double &  out 
)

Definition at line 53 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
i32 out 
)

Definition at line 63 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
u32 out 
)

Definition at line 73 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
u16 out 
)

Definition at line 83 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
CColor out 
)

Definition at line 86 of file EngineScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
u8 out 
)

Definition at line 93 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
CScriptVal out 
)

Definition at line 104 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
CScriptValRooted out 
)

Definition at line 110 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
fixed out 
)

Definition at line 126 of file EngineScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
Path out 
)

Definition at line 130 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
CFixedVector3D out 
)

Definition at line 144 of file EngineScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
Entity out 
)

Definition at line 153 of file ScriptConversions.cpp.

template<>
bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  v,
CFixedVector2D out 
)

Definition at line 181 of file EngineScriptConversions.cpp.

template<typename T >
static bool ScriptInterface::FromJSVal ( JSContext *  cx,
jsval  val,
T ret 
)
static

Convert a jsval to a C++ type.

(This might trigger GC.)

void * ScriptInterface::GetCallbackData ( JSContext *  cx)
static

Definition at line 622 of file ScriptInterface.cpp.

JSClass * ScriptInterface::GetClass ( JSContext *  cx,
JSObject *  obj 
)
staticprivate

Definition at line 1154 of file ScriptInterface.cpp.

JSContext * ScriptInterface::GetContext ( ) const

Definition at line 672 of file ScriptInterface.cpp.

JSClass * ScriptInterface::GetGlobalClass ( )

Definition at line 765 of file ScriptInterface.cpp.

jsval ScriptInterface::GetGlobalObject ( )

Definition at line 760 of file ScriptInterface.cpp.

void * ScriptInterface::GetPrivate ( JSContext *  cx,
JSObject *  obj 
)
staticprivate

Definition at line 1161 of file ScriptInterface.cpp.

template<typename T >
bool ScriptInterface::GetProperty ( jsval  obj,
const char *  name,
T out 
)

Get the named property on the given object.

Definition at line 474 of file ScriptInterface.h.

bool ScriptInterface::GetProperty_ ( jsval  obj,
const char *  name,
jsval &  value 
)
private

Definition at line 823 of file ScriptInterface.cpp.

template<typename T >
bool ScriptInterface::GetPropertyInt ( jsval  obj,
int  name,
T out 
)

Get the integer-named property on the given object.

Definition at line 483 of file ScriptInterface.h.

bool ScriptInterface::GetPropertyInt_ ( jsval  obj,
int  name,
jsval &  value 
)
private

Definition at line 834 of file ScriptInterface.cpp.

JSRuntime * ScriptInterface::GetRuntime ( ) const

Definition at line 677 of file ScriptInterface.cpp.

bool ScriptInterface::HasProperty ( jsval  obj,
const char *  name 
)

Check the named property has been defined on the given object.

Definition at line 845 of file ScriptInterface.cpp.

bool ScriptInterface::IsExceptionPending ( JSContext *  cx)
staticprivate

Definition at line 1149 of file ScriptInterface.cpp.

bool ScriptInterface::LoadGlobalScript ( const VfsPath filename,
const std::string &  code 
)

Load and execute the given script in the global scope.

Parameters
filenameName for debugging purposes (not used to load the file)
codeJS code to execute
Returns
true on successful compilation and execution; false otherwise

Definition at line 936 of file ScriptInterface.cpp.

bool ScriptInterface::LoadGlobalScriptFile ( const VfsPath path)

Load and execute the given script in the global scope.

Returns
true on successful compilation and execution; false otherwise

Definition at line 952 of file ScriptInterface.cpp.

bool ScriptInterface::LoadGlobalScripts ( )

Load global scripts that most script contexts need, located in the /globalscripts directory.

VFS must be initialized.

Definition at line 627 of file ScriptInterface.cpp.

bool ScriptInterface::LoadScript ( const VfsPath filename,
const std::string &  code 
)

Load and execute the given script in a new function scope.

Parameters
filenameName for debugging purposes (not used to load the file)
codeJS code to execute
Returns
true on successful compilation and execution; false otherwise

Definition at line 915 of file ScriptInterface.cpp.

void ScriptInterface::MaybeGC ( )

MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to be worth the amount of time it would take.

Definition at line 1177 of file ScriptInterface.cpp.

jsval ScriptInterface::NewObjectFromConstructor ( jsval  ctor)

Create an object as with CallConstructor except don't actually execute the constructor function.

Returns
The new object; or JSVAL_VOID on failure, and logs an error message

Definition at line 701 of file ScriptInterface.cpp.

CScriptValRooted ScriptInterface::ParseJSON ( const std::string &  string_utf8)

Parse a UTF-8-encoded JSON string.

Returns the undefined value on error.

Definition at line 1009 of file ScriptInterface.cpp.

CScriptValRooted ScriptInterface::ReadJSONFile ( const VfsPath path)

Read a JSON file.

Returns the undefined value on error.

Definition at line 1037 of file ScriptInterface.cpp.

jsval ScriptInterface::ReadStructuredClone ( const shared_ptr< StructuredClone > &  ptr)

Definition at line 1333 of file ScriptInterface.cpp.

void ScriptInterface::Register ( const char *  name,
JSNative  fptr,
size_t  nargs 
)
private

Definition at line 667 of file ScriptInterface.cpp.

AutoGCRooter * ScriptInterface::ReplaceAutoGCRooter ( AutoGCRooter rooter)

Definition at line 682 of file ScriptInterface.cpp.

bool ScriptInterface::ReplaceNondeterministicRNG ( boost::rand48 &  rng)

Replace the default JS random number geenrator with a seeded, network-sync'd one.

Definition at line 648 of file ScriptInterface.cpp.

void ScriptInterface::ReportError ( const char *  msg)

Report the given error message through the JS error reporting mechanism, and throw a JS exception.

(Callers can check IsPendingException, and must return JS_FALSE in that case to propagate the exception.)

Definition at line 1136 of file ScriptInterface.cpp.

void ScriptInterface::SetCallbackData ( void *  cbdata)

Definition at line 617 of file ScriptInterface.cpp.

template<typename T >
bool ScriptInterface::SetGlobal ( const char *  name,
const T value,
bool  replace = false 
)

Set the named property on the global object.

If replace is true, an existing property will be overwritten; otherwise attempts to set an already-defined value will fail.

Definition at line 456 of file ScriptInterface.h.

bool ScriptInterface::SetGlobal_ ( const char *  name,
jsval  value,
bool  replace 
)
private

Definition at line 770 of file ScriptInterface.cpp.

template<typename T >
bool ScriptInterface::SetProperty ( jsval  obj,
const char *  name,
const T value,
bool  constant = false,
bool  enumerate = true 
)

Set the named property on the given object.

Optionally makes it {ReadOnly, DontDelete, DontEnum}.

Definition at line 462 of file ScriptInterface.h.

bool ScriptInterface::SetProperty_ ( jsval  obj,
const char *  name,
jsval  value,
bool  readonly,
bool  enumerate 
)
private

Definition at line 789 of file ScriptInterface.cpp.

template<typename T >
bool ScriptInterface::SetPropertyInt ( jsval  obj,
int  name,
const T value,
bool  constant = false,
bool  enumerate = true 
)

Set the integer-named property on the given object.

Optionally makes it {ReadOnly, DontDelete, DontEnum}.

Definition at line 468 of file ScriptInterface.h.

bool ScriptInterface::SetPropertyInt_ ( jsval  obj,
int  name,
jsval  value,
bool  readonly,
bool  enumerate 
)
private

Definition at line 806 of file ScriptInterface.cpp.

bool ScriptInterface::SetPrototype ( jsval  obj,
jsval  proto 
)

Definition at line 897 of file ScriptInterface.cpp.

void ScriptInterface::ShutDown ( )
static

Shut down the JS system to clean up memory.

Must only be called when there are no ScriptInterfaces alive.

Definition at line 612 of file ScriptInterface.cpp.

std::string ScriptInterface::StringifyJSON ( jsval  obj,
bool  indent = true 
)

Stringify to a JSON string, UTF-8 encoded.

Returns an empty string on error.

Definition at line 1087 of file ScriptInterface.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
SDL_Event_ const &  val 
)

Definition at line 32 of file GuiScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
IComponent *const &  val 
)

Definition at line 35 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
CParamNode const &  val 
)

Definition at line 66 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CParamNode *const &  val 
)

Definition at line 78 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
CColor const &  val 
)

Definition at line 107 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
IGUIObject *const &  val 
)

Definition at line 134 of file GuiScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const fixed val 
)

Definition at line 137 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CFixedVector3D val 
)

Definition at line 164 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const bool &  val 
)

Definition at line 179 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const float &  val 
)

Definition at line 184 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const double &  val 
)

Definition at line 191 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const i32 val 
)

Definition at line 198 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CFixedVector2D val 
)

Definition at line 198 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const u16 val 
)

Definition at line 204 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const u8 val 
)

Definition at line 209 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const u32 val 
)

Definition at line 214 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CScriptVal val 
)

Definition at line 224 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CScriptValRooted val 
)

Definition at line 229 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const Grid< u8 > &  val 
)

Definition at line 240 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const Path val 
)

Definition at line 243 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const Grid< u16 > &  val 
)

Definition at line 245 of file EngineScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const wchar_t *const &  val 
)

Definition at line 256 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const char *const &  val 
)

Definition at line 261 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CStrW &  val 
)

Definition at line 269 of file ScriptConversions.cpp.

template<>
jsval ScriptInterface::ToJSVal ( JSContext *  cx,
const CStr8 &  val 
)

Definition at line 274 of file ScriptConversions.cpp.

template<typename T >
static jsval ScriptInterface::ToJSVal ( JSContext *  cx,
T const &  val 
)
static

Convert a C++ type to a jsval.

(This might trigger GC. The return value must be rooted if you don't want it to be collected.)

std::wstring ScriptInterface::ToString ( jsval  obj,
bool  pretty = false 
)

Definition at line 1102 of file ScriptInterface.cpp.

shared_ptr< ScriptInterface::StructuredClone > ScriptInterface::WriteStructuredClone ( jsval  v)

Definition at line 1317 of file ScriptInterface.cpp.

Member Data Documentation

std::auto_ptr<ScriptInterface_impl> ScriptInterface::m
private

Definition at line 338 of file ScriptInterface.h.


The documentation for this class was generated from the following files: