ScriptableComplex.h: ScriptingHost already includes SpiderMonkey.h

scriptglue: additional refactoring
scriptinghost: remove useless GC function
SpiderMonkey.h: more dox

This was SVN commit r2497.
This commit is contained in:
janwas 2005-07-20 04:53:58 +00:00
parent 0b193342e7
commit f715e6c226
6 changed files with 77 additions and 75 deletions

View File

@ -2,9 +2,6 @@
#include "StringConvert.h"
#include "lib/types.h"
#include "scripting/SpiderMonkey.h"
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN

View File

@ -125,7 +125,7 @@ JSBool WriteLog(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDP
// Entity
//-----------------------------------------------------------------------------
// Look up an Entity by entity handle.
// Retrieve the entity currently occupying the specified handle.
// params: handle [int]
// returns: entity
JSBool getEntityByHandle( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval )
@ -186,6 +186,35 @@ JSBool getEntityTemplate( JSContext* cx, JSObject*, uint argc, jsval* argv, jsva
}
// Issue a command (network message) to an entity or collection.
// params: either an entity- or entity collection object, message ID [int],
// any further params needed by CNetMessage::CommandFromJSArgs
// returns: command in serialized form [string]
JSBool issueCommand( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval )
{
REQUIRE_MIN_PARAMS(2, issueCommand);
debug_assert(JSVAL_IS_OBJECT(argv[0]));
*rval = JSVAL_NULL;
CEntityList entities;
if (JS_GetClass(JSVAL_TO_OBJECT(argv[0])) == &CEntity::JSI_class)
entities.push_back( (ToNative<CEntity>(argv[0])) ->me);
else
entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0]));
CNetMessage *msg = CNetMessage::CommandFromJSArgs(entities, cx, argc-1, argv+1);
if (msg)
{
g_Console->InsertMessage(L"issueCommand: %hs", msg->GetString().c_str());
g_Game->GetSimulation()->QueueLocalCommand(msg);
*rval = g_ScriptingHost.UCStringToValue(msg->GetString());
}
return JS_TRUE;
}
//-----------------------------------------------------------------------------
// Events
//-----------------------------------------------------------------------------
@ -436,6 +465,11 @@ JSBool endGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPA
// Internationalization
//-----------------------------------------------------------------------------
// these remain here instead of in the i18n tree because they are
// really related to the engine's use of them, as opposed to i18n itself.
// contrariwise, translate() cannot be moved here because that would
// make i18n dependent on this code and therefore harder to reuse.
// Replaces the current language (locale) with a new one.
// params: language id [string] as in I18n::LoadLanguage
// returns:
@ -509,7 +543,7 @@ JSBool forceGC( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rva
//-----------------------------------------------------------------------------
// Misc. Script System
// GUI
//-----------------------------------------------------------------------------
// Returns the sort-of-global object associated with the current GUI.
@ -526,20 +560,6 @@ JSBool getGUIGlobal( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rv
}
// Returns the global object.
// params:
// returns: global object
// notes:
// - Useful for accessing an object from another scope.
JSBool getGlobal( JSContext* cx, JSObject* globalObject, uint argc, jsval* argv, jsval* rval )
{
REQUIRE_NO_PARAMS(getGlobal);
*rval = OBJECT_TO_JSVAL( globalObject );
return( JS_TRUE );
}
//-----------------------------------------------------------------------------
// Misc. Engine Interface
//-----------------------------------------------------------------------------
@ -641,7 +661,7 @@ JSBool _lodbias( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED
}
// Set the lookat target of the game camera.
// Focus the game camera on a given position.
// params: target position vector [CVector3D]
// returns: success [bool]
JSBool setCameraTarget( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
@ -693,35 +713,6 @@ JSBool buildTime( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval
}
// Issue a command (network message) to an entity or collection.
// params: either an entity- or entity collection object, message ID [int],
// any further params needed by CNetMessage::CommandFromJSArgs
// returns: command in serialized form [string]
JSBool issueCommand( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval )
{
REQUIRE_MIN_PARAMS(2, issueCommand);
debug_assert(JSVAL_IS_OBJECT(argv[0]));
*rval = JSVAL_NULL;
CEntityList entities;
if (JS_GetClass(JSVAL_TO_OBJECT(argv[0])) == &CEntity::JSI_class)
entities.push_back( (ToNative<CEntity>(argv[0])) ->me);
else
entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0]));
CNetMessage *msg = CNetMessage::CommandFromJSArgs(entities, cx, argc-1, argv+1);
if (msg)
{
g_Console->InsertMessage(L"issueCommand: %hs", msg->GetString().c_str());
g_Game->GetSimulation()->QueueLocalCommand(msg);
*rval = g_ScriptingHost.UCStringToValue(msg->GetString());
}
return JS_TRUE;
}
// Return distance between 2 points.
// params: 2 position vectors [CVector3D]
// returns: Euclidean distance [float]
@ -737,6 +728,20 @@ JSBool v3dist( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval
}
// Returns the global object.
// params:
// returns: global object
// notes:
// - Useful for accessing an object from another scope.
JSBool getGlobal( JSContext* cx, JSObject* globalObject, uint argc, jsval* argv, jsval* rval )
{
REQUIRE_NO_PARAMS(getGlobal);
*rval = OBJECT_TO_JSVAL( globalObject );
return( JS_TRUE );
}
//-----------------------------------------------------------------------------
// function table
//-----------------------------------------------------------------------------
@ -753,13 +758,22 @@ JSBool v3dist( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval
JSFunctionSpec ScriptFunctionTable[] =
{
// Output
JS_FUNC(writeLog, WriteLog, 1)
// Console
JS_FUNC(writeConsole, JSI_Console::writeConsole, 1) // external
// Entity
JS_FUNC(getEntityByHandle, getEntityByHandle, 1)
JS_FUNC(getEntityTemplate, getEntityTemplate, 1)
JS_FUNC(issueCommand, issueCommand, 2)
// Camera
JS_FUNC(setCameraTarget, setCameraTarget, 1)
// GUI
#ifndef NO_GUI
JS_FUNC(getGUIObjectByName, JSI_IGUIObject::getByName, 1) // external
JS_FUNC(getGUIGlobal, getGUIGlobal, 0)
#endif
// Events
JS_FUNC(addGlobalHandler, AddGlobalHandler, 2)
@ -786,31 +800,26 @@ JSFunctionSpec ScriptFunctionTable[] =
// Internationalization
JS_FUNC(loadLanguage, loadLanguage, 1)
JS_FUNC(getLanguageID, getLanguageID, 0)
// note: i18n/ScriptInterface.cpp registers translate() itself.
// rationale: see implementation section above.
// Debug
JS_FUNC(crash, crash, 0)
JS_FUNC(forceGC, forceGC, 0)
// Misc. Script System
JS_FUNC(getGlobal, getGlobal, 0)
JS_FUNC(getGUIGlobal, getGUIGlobal, 0)
#ifndef NO_GUI
JS_FUNC(getGUIObjectByName, JSI_IGUIObject::getByName, 1) // external
#endif
// Misc. Engine Interface
JS_FUNC(writeLog, WriteLog, 1)
JS_FUNC(exit, exitProgram, 0)
JS_FUNC(vmem, vmem, 0)
JS_FUNC(_rewriteMaps, _rewriteMaps, 0)
JS_FUNC(_lodbias, _lodbias, 0)
JS_FUNC(setCursor, setCursor, 1)
JS_FUNC(setCameraTarget, setCameraTarget, 1)
JS_FUNC(getFPS, getFPS, 0)
// Miscellany
JS_FUNC(v3dist, v3dist, 2)
JS_FUNC(issueCommand, issueCommand, 2)
JS_FUNC(buildTime, buildTime, 0)
JS_FUNC(getGlobal, getGlobal, 0)
// end of table marker
{0, 0, 0, 0, 0}

View File

@ -6,8 +6,6 @@
#include "scripting/ScriptingHost.h"
#include "JSConversions.h"
#include "scripting/SpiderMonkey.h"
#include <set>
#ifndef SCRIPTABLE_COMPLEX_INCLUDED

View File

@ -384,11 +384,6 @@ void ScriptingHost::ErrorReporter(JSContext * context, const char * message, JSE
}
}
void ScriptingHost::_CollectGarbage()
{
JS_GC(m_Context);
}
#ifndef NDEBUG
void* ScriptingHost::jshook_script( JSContext* cx, JSStackFrame* fp, JSBool before, JSBool* ok, void* closure )

View File

@ -71,7 +71,6 @@ private:
std::map < std::string, CustomType > m_CustomObjectTypes;
void _CollectGarbage();
#ifndef NDEBUG
// A hook to capture script calls
static void* jshook_script( JSContext* cx, JSStackFrame* fp, JSBool before, JSBool* ok, void* closure );

View File

@ -1,10 +1,14 @@
// master header for the SpiderMonkey Javascript library.
// include this instead of accessing any <js*.h> headers directly.
// rationale: these headers require an OS macro to be set (XP_*).
// since this is specific to SpiderMonkey, we don't want to hide the fact in
// some obscure header that's pulled in via PCH (would make reuse harder).
// we take care of it below.
// Master header for the SpiderMonkey Javascript library.
//
// Include this instead of accessing any <js*.h> headers directly.
// Rationale: they require an OS macro to be set (XP_*).
// Since this is specific to SpiderMonkey, we don't want to saddle
// another obscure header with it (would make reuse harder).
// Instead, do it here where the purpose is clear.
//
// This doesn't go in ScriptingHost.h because some other files
// (notably precompiled.h and i18n/ScriptInterface.cpp) want only these
// definitions without pulling in the whole of ScriptingHost.
// jstypes.h (included via jsapi.h) requires we define
// "one of XP_BEOS, XP_MAC, XP_OS2, XP_WIN or XP_UNIX".