2004-10-07 21:35:08 +02:00
|
|
|
// A generic type and some helper functions
|
|
|
|
// for scripts
|
|
|
|
|
|
|
|
// Mark Thompson (mark@wildfiregames.com / mot20@cam.ac.uk)
|
|
|
|
|
|
|
|
#ifndef SCRIPTOBJECT_INCLUDED
|
|
|
|
#define SCRIPTOBJECT_INCLUDED
|
|
|
|
|
|
|
|
#include "CStr.h"
|
|
|
|
#include "scripting/ScriptingHost.h"
|
|
|
|
#include "EntityHandles.h"
|
|
|
|
#include "scripting/JSInterface_Entity.h"
|
2004-10-23 16:39:28 +02:00
|
|
|
#include "scripting/DOMEvent.h"
|
2004-10-07 21:35:08 +02:00
|
|
|
|
|
|
|
class CScriptObject
|
|
|
|
{
|
|
|
|
JSFunction* Function;
|
2004-10-23 16:39:28 +02:00
|
|
|
public:
|
2004-10-07 21:35:08 +02:00
|
|
|
|
|
|
|
CScriptObject();
|
|
|
|
CScriptObject( JSFunction* _Function );
|
|
|
|
CScriptObject( jsval v );
|
2004-10-23 16:39:28 +02:00
|
|
|
|
|
|
|
// Initialize in various ways: from a JS function, a string to be compiled, or a jsval containing either.
|
2004-10-07 21:35:08 +02:00
|
|
|
void SetFunction( JSFunction* _Function );
|
|
|
|
void SetJSVal( jsval v );
|
2004-10-23 16:39:28 +02:00
|
|
|
void Compile( CStrW FileNameTag, CStrW FunctionBody );
|
|
|
|
|
2004-10-07 21:35:08 +02:00
|
|
|
inline bool Defined();
|
2004-10-23 16:39:28 +02:00
|
|
|
|
|
|
|
// JSObject wrapping the function if it's defined, NULL if it isn't.
|
|
|
|
JSObject* GetFunctionObject();
|
|
|
|
|
2004-10-07 21:35:08 +02:00
|
|
|
// Executes a script attached to a JS object.
|
|
|
|
// Returns false if the script isn't defined, if the script can't be executed,
|
|
|
|
// otherwise true. Script return value is in rval.
|
|
|
|
bool Run( JSObject* Context, jsval* rval );
|
|
|
|
// This variant casts script return value to a boolean, and passes it back.
|
|
|
|
bool Run( JSObject* Context );
|
2004-10-23 16:39:28 +02:00
|
|
|
|
|
|
|
// Treat this as an event handler and dispatch an event to it.
|
|
|
|
void DispatchEvent( JSObject* Context, CScriptEvent* evt );
|
2004-10-07 21:35:08 +02:00
|
|
|
};
|
|
|
|
|
2004-11-07 22:30:47 +01:00
|
|
|
#endif
|