Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoJavaScriptEngine.h
1#ifndef COIN_SOJAVASCRIPTENGINE_H
2#define COIN_SOJAVASCRIPTENGINE_H
3
4/**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25\**************************************************************************/
26
27#include <Inventor/misc/SoScriptEngine.h>
28#include <Inventor/C/glue/spidermonkey.h>
29#include <Inventor/lists/SbList.h>
30
31// *************************************************************************
32
33#define COIN_JAVASCRIPT_RUNTIME_MAXBYTES 4194304
34
35// *************************************************************************
36
37typedef void SoJSfield2jsvalFunc(JSContext *, const SoField *, jsval *);
38typedef SbBool SoJSjsval2field2Func(JSContext *, const jsval, SoField *);
39typedef JSObject * SoJSWrapperInitFunc(JSContext *, JSObject * obj);
40
41// *************************************************************************
42
43class COIN_DLL_API SoJavaScriptEngine : public SoScriptEngine {
44
45public:
46 SoJavaScriptEngine();
47 virtual ~SoJavaScriptEngine();
48
49 virtual SbBool executeScript(const SbName & name,
50 const SbString & script) const;
51 virtual SbBool executeFile(const SbName & filename) const;
52 virtual SbBool executeFunction(const SbName &name, int argc,
53 const SoField * argv,
54 SoField * rval = NULL) const;
55
56 virtual SbBool setScriptField(const SbName & name, const SoField * f) const;
57 virtual SbBool unsetScriptField(const SbName & name) const;
58 virtual SbBool getScriptField(const SbName & name, SoField * f) const;
59 virtual SbBool hasScriptField(const SbName & name) const;
60
61 // Everything under here is javascript specific
62
63 static SoJavaScriptEngine *getEngine(JSContext * cx);
64
65 SbBool field2jsval(const SoField * f, jsval * v) const;
66 SbBool jsval2field(const jsval v, SoField * f) const;
67 void enableAutoNodeUnref(SbBool onoff);
68 SbBool getAutoNodeUnrefState(void) const;
69
70 static SbBool init(uint32_t maxbytes = COIN_JAVASCRIPT_RUNTIME_MAXBYTES);
71 static void shutdown(void);
72 static SbBool debug(void);
73
74 static JSRuntime * getRuntime(void);
75 JSContext * getContext(void) const;
76 JSObject * getGlobal(void) const;
77
78 void addHandler(const SoType & type, SoJSWrapperInitFunc * init,
79 SoJSfield2jsvalFunc * field2jsval,
80 SoJSjsval2field2Func * jsval2field);
81
82protected:
83 static void setRuntime(JSRuntime * runtime);
84 void setContext(JSContext * context);
85 void setGlobal(JSObject * global);
86
87private:
88 class SoJavaScriptEngineP * pimpl;
89 friend class SoJavaScriptEngineP;
90};
91
92#endif // !COIN_SOJAVASCRIPTENGINE_H
The SbName class stores strings by reference.
Definition SbName.h:31
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:42
The SoField class is the top-level abstract base class for fields.
Definition SoField.h:38
The SoType class is the basis for the run-time type system in Coin.
Definition SoType.h:50

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.