30 #if !(defined(JAVASCRIPT_STUB) || defined(JAVASCRIPT_DUK))
34 #include <libFreeWRL.h>
36 #include "../vrml_parser/Structs.h"
37 #include "../main/headers.h"
38 #include "../vrml_parser/CParseGeneral.h"
39 #include "../vrml_parser/CRoutes.h"
40 #include "../main/Snapshot.h"
41 #include "../scenegraph/Collision.h"
42 #include "../scenegraph/quaternion.h"
43 #include "../scenegraph/Viewer.h"
44 #include "../input/EAIHelpers.h"
45 #include "../input/SensInterps.h"
46 #include "../x3d_parser/Bindable.h"
52 #include "jsVRMLClasses.h"
53 #include "jsVRMLBrowser.h"
58 #ifndef JSCLASS_GLOBAL_FLAGS
60 #define JSCLASS_GLOBAL_FLAGS 0
63 #ifdef JAVASCRIPTVERBOSE
64 int ActualrunScript(
int num,
char *script, jsval *rval,
char *fn,
int line);
66 int ActualrunScript(
int num,
char *script, jsval *rval);
70 static JSClass staticGlobalClass = {
76 JS_StrictPropertyStub,
101 jsval JSglobal_return_value;
107 void *JScript_constructor(){
108 void *v = MALLOCV(
sizeof(
struct pJScript));
109 memset(v,0,
sizeof(
struct pJScript));
112 void JScript_init(
struct tJScript *t){
114 t->JSglobal_return_val = NULL;
116 t->prv = JScript_constructor();
121 memcpy(&p->globalClass,&staticGlobalClass,
sizeof(staticGlobalClass));
122 t->JSglobal_return_val = &p->JSglobal_return_value;
129 void js_cleanup_script_context(
int counter){
133 CLEANUP_JAVASCRIPT(getScriptControlIndex(counter)->cx);
145 void process_eventsProcessed() {
152 for (counter = 0; counter <= tg->CRoutes.max_script_found_and_initialized; counter++) {
153 scriptcontrol = getScriptControlIndex(counter);
154 if(scriptcontrol->thisScriptType != NOSCRIPT ){
155 if (scriptcontrol->eventsProcessed == NULL) {
156 #if defined(JS_THREADSAFE)
157 JS_BeginRequest(scriptcontrol->cx);
159 scriptcontrol->eventsProcessed = (
void *)JS_CompileScript(
162 "eventsProcessed()", strlen (
"eventsProcessed()"),
163 "compile eventsProcessed()", 1);
164 #if JS_VERSION >= 185
165 if (!JS_AddObjectRoot(scriptcontrol->cx,(JSSCRIPT**)(&scriptcontrol->eventsProcessed))) {
166 printf (
"can not add object root for compiled eventsProcessed() for script %d\n",counter);
169 #if defined(JS_THREADSAFE)
170 JS_EndRequest(scriptcontrol->cx);
174 #if defined(JS_THREADSAFE)
175 JS_BeginRequest(scriptcontrol->cx);
177 if (!JS_ExecuteScript( scriptcontrol->cx,
179 scriptcontrol->eventsProcessed, &retval)) {
180 #if defined(_MSC_VER)
181 printf (
"can not run eventsProcessed() for script %d thread %u\n",counter,(
unsigned int)pthread_self().x);
183 printf (
"can not run eventsProcessed() for script %d thread %p\n",counter,(
void *)pthread_self());
186 #if defined(JS_THREADSAFE)
187 JS_EndRequest(scriptcontrol->cx);
198 void jsClearScriptControlEntries(
int num)
201 ScriptControl = getScriptControlIndex(num);
202 if (ScriptControl->eventsProcessed != NULL) {
203 #if JS_VERSION >= 185
204 if (ScriptControl->cx != NULL) {
205 JS_RemoveObjectRoot(ScriptControl->cx,(JSSCRIPT**)(&ScriptControl->eventsProcessed));
208 ScriptControl->eventsProcessed = NULL;
216 #define MAX_RUNTIME_BYTES 0x4000000L
219 #define STACK_CHUNK_SIZE 8192
221 static int JSaddGlobalECMANativeProperty(
int num,
const char *name);
222 static int JSaddGlobalAssignProperty(
int num,
const char *name,
const char *str);
257 static char *DefaultScriptMethods =
"function initialize() {}; " \
258 " function shutdown() {}; " \
259 " function eventsProcessed() {}; " \
260 " TRUE=true; FALSE=false; " \
261 " function print(x) {Browser.print(x)}; " \
262 " function println(x) {Browser.println(x)}; " \
263 " function getName() {return Browser.getName()}; "\
264 " function getVersion() {return Browser.getVersion()}; "\
265 " function getCurrentSpeed() {return Browser.getCurrentSpeed()}; "\
266 " function getCurrentFrameRate() {return Browser.getCurrentFrameRate()}; "\
267 " function getWorldURL() {return Browser.getWorldURL()}; "\
268 " function replaceWorld(x) {Browser.replaceWorld(x)}; "\
269 " function loadURL(x,y) {Browser.loadURL(x,y)}; "\
270 " function setDescription(x) {Browser.setDescription(x)}; "\
271 " function createVrmlFromString(x) {Browser.createVrmlFromString(x)}; "\
272 " function createVrmlFromURL(x,y,z) {Browser.createVrmlFromURL(x,y,z)}; "\
273 " function createX3DFromString(x) {Browser.createX3DFromString(x)}; "\
274 " function createX3DFromURL(x,y,z) {Browser.createX3DFromURL(x,y,z)}; "\
275 " function addRoute(a,b,c,d) {Browser.addRoute(a,b,c,d)}; "\
276 " function deleteRoute(a,b,c,d) {Browser.deleteRoute(a,b,c,d)}; "
282 return p->runtime ? 1 : 0;
284 void JSDeleteScriptContext(
int num){
288 ScriptControl = getScriptControlIndex(num);
289 #if JS_VERSION >= 185
290 if (ScriptControl->eventsProcessed != NULL) {
291 JS_RemoveObjectRoot(ScriptControl->cx,(JSSCRIPT **)(&ScriptControl->eventsProcessed));
294 JS_DestroyContextMaybeGC(ScriptControl->cx);
300 JS_DestroyRuntime(p->runtime);
312 void JSCreateScriptContext(
int num) {
315 JSObject *_globalObj;
320 ScriptControl = getScriptControlIndex(num);
323 if (p->runtime == NULL) {
324 p->runtime = JS_NewRuntime(MAX_RUNTIME_BYTES);
325 if (!p->runtime) freewrlDie(
"JS_NewRuntime failed");
327 #ifdef JAVASCRIPTVERBOSE
328 printf(
"\tJS runtime created,\n");
333 _context = JS_NewContext(p->runtime, STACK_CHUNK_SIZE);
334 if (!_context) freewrlDie(
"JS_NewContext failed");
336 #ifdef JAVASCRIPTVERBOSE
337 printf(
"\tJS context created,\n");
340 #if defined(JS_THREADSAFE)
341 JS_BeginRequest(_context);
343 #if JS_VERSION >= 185
345 _globalObj = JS_NewCompartmentAndGlobalObject(_context, &p->globalClass, NULL);
348 JS_SetGlobalObject(_context,cs->glob);
349 _globalObj = JS_NewGlobalObject(_context,&p->globalClass);
350 JS_SetGlobalObject(_context,_globalObj);
353 _globalObj = JS_NewObject(_context, &p->globalClass, NULL, NULL);
355 #if defined(JS_THREADSAFE)
356 JS_EndRequest(_context);
358 if (!_globalObj) freewrlDie(
"JS_NewObject failed");
360 #ifdef JAVASCRIPTVERBOSE
361 printf(
"\tJS global object created,\n");
366 #if defined(JS_THREADSAFE)
367 JS_BeginRequest(_context);
369 if (!JS_InitStandardClasses(_context, _globalObj))
370 #if defined(JS_THREADSAFE)
371 { JS_EndRequest(_context);
373 freewrlDie(
"JS_InitStandardClasses failed");
374 #if defined(JS_THREADSAFE)
376 JS_EndRequest(_context);
379 #ifdef JAVASCRIPTVERBOSE
380 printf(
"\tJS standard classes initialized,\n");
383 #ifdef JAVASCRIPTVERBOSE
387 JS_SetErrorReporter(_context, errorReporter);
389 #ifdef JAVASCRIPTVERBOSE
390 printf(
"\tJS error reporter set,\n");
396 ScriptControl->cx = _context;
397 ScriptControl->glob = _globalObj;
400 #if defined(JS_THREADSAFE)
401 JS_BeginRequest(_context);
403 if (!loadVrmlClasses(_context, _globalObj))
404 #if defined(JS_THREADSAFE)
405 { JS_EndRequest(_context);
407 freewrlDie(
"loadVrmlClasses failed");
408 #if defined(JS_THREADSAFE)
410 JS_EndRequest(_context);
415 #ifdef JAVASCRIPTVERBOSE
416 printf(
"\tVRML classes loaded,\n");
419 #if defined(JS_THREADSAFE)
420 JS_BeginRequest(_context);
422 if (!VrmlBrowserInit(_context, _globalObj, br))
423 #if defined(JS_THREADSAFE)
424 { JS_EndRequest(_context);
426 freewrlDie(
"VrmlBrowserInit failed");
427 #if defined(JS_THREADSAFE)
429 JS_EndRequest(_context);
433 #ifdef JAVASCRIPTVERBOSE
434 printf(
"\tVRML Browser interface loaded,\n");
438 if (!ACTUALRUNSCRIPT(num,DefaultScriptMethods,&rval))
439 cleanupDie(num,
"runScript failed in VRML::newJS DefaultScriptMethods");
442 CRoutes_js_new (num, JAVASCRIPT);
444 #ifdef JAVASCRIPTVERBOSE
445 printf(
"\tVRML browser initialized, thread %u\n",pthread_self());
451 #ifdef JAVASCRIPTVERBOSE
452 int ActualrunScript(
int num,
char *script, jsval *rval,
char *fn,
int line) {
454 int ActualrunScript(
int num,
char *script, jsval *rval) {
458 JSObject *_globalObj;
461 ScriptControl = getScriptControlIndex(num);
464 _context = (JSContext*)ScriptControl->cx;
465 _globalObj = (JSObject*)ScriptControl->glob;
467 #ifdef JAVASCRIPTVERBOSE
468 printf(
"ActualrunScript script called at %s:%d num: %d cx %p \"%s\", \n",
469 fn, line, num, _context, script);
472 #if defined(JS_THREADSAFE)
473 JS_BeginRequest(_context);
475 CLEANUP_JAVASCRIPT(_context)
476 #if defined(JS_THREADSAFE)
477 JS_EndRequest(_context);
480 len = (int) strlen(script);
481 #if defined(JS_THREADSAFE)
482 JS_BeginRequest(_context);
484 if (!JS_EvaluateScript(_context, _globalObj, script, len, FNAME_STUB, LINENO_STUB, rval)) {
485 printf (
"ActualrunScript - JS_EvaluateScript failed for %s", script);
487 ConsoleMessage (
"ActualrunScript - JS_EvaluateScript failed for %s", script);
488 #if defined(JS_THREADSAFE)
489 JS_EndRequest(_context);
492 #if defined(JS_THREADSAFE)
494 JS_EndRequest(_context);
498 #ifdef JAVASCRIPTVERBOSE
499 printf (
"runscript passed\n");
505 int jsActualrunScript(
int num,
char *script) {
507 return ACTUALRUNSCRIPT(num,script,&rval);
511 int jsrrunScript(JSContext *_context, JSObject *_globalObj,
char *script, jsval *rval) {
515 #ifdef JAVASCRIPTVERBOSE
516 printf(
"jsrrunScript script cx %p \"%s\", \n",
520 len = (int) strlen(script);
521 #if defined(JS_THREADSAFE)
522 JS_BeginRequest(_context);
524 if (!JS_EvaluateScript(_context, _globalObj, script, len,
525 FNAME_STUB, LINENO_STUB, rval)) {
526 ConsoleMessage (
"jsrunScript - JS_EvaluateScript failed for %s", script);
527 #if defined(JS_THREADSAFE)
528 JS_EndRequest(_context);
531 #if defined(JS_THREADSAFE)
533 JS_EndRequest(_context);
537 #ifdef JAVASCRIPTVERBOSE
538 printf (
"runscript passed\n");
545 void *SFNodeNativeNew()
553 ptr->valueChanged = 0;
554 ptr->X3DString = NULL;
555 ptr->fieldsExpanded = FALSE;
560 int SFNodeNativeAssign(
void *top,
void *fromp)
569 to->handle = from->handle;
570 to->X3DString = STRDUP(from->X3DString);
572 #ifdef JAVASCRIPTVERBOSE
573 printf (
"SFNodeNativeAssign, copied %p to %p, handle %p, string %s\n", from, to, to->handle, to->X3DString);
577 to->X3DString = STRDUP(
"from a NULL assignment");
583 void *SFColorRGBANativeNew()
587 ptr->valueChanged = 0;
591 void SFColorRGBANativeAssign(
void *top,
void *fromp)
599 void *SFColorNativeNew()
603 ptr->valueChanged = 0;
607 void SFColorNativeAssign(
void *top,
void *fromp)
615 void *SFImageNativeNew()
619 ptr->valueChanged = 0;
623 void SFImageNativeAssign(
void *top,
void *fromp)
633 void *SFRotationNativeNew()
637 ptr->valueChanged = 0;
641 void SFRotationNativeAssign(
void *top,
void *fromp)
649 void *SFVec2fNativeNew()
653 ptr->valueChanged = 0;
657 void SFVec2fNativeAssign(
void *top,
void *fromp)
665 void *SFVec3fNativeNew() {
668 ptr->valueChanged = 0;
672 void SFVec3fNativeAssign(
void *top,
void *fromp) {
679 void *SFVec3dNativeNew() {
682 ptr->valueChanged = 0;
686 void SFVec3dNativeAssign(
void *top,
void *fromp) {
693 void *SFVec4fNativeNew() {
696 ptr->valueChanged = 0;
700 void SFVec4fNativeAssign(
void *top,
void *fromp) {
707 void *SFVec4dNativeNew() {
710 ptr->valueChanged = 0;
714 void SFVec4dNativeAssign(
void *top,
void *fromp) {
723 static char* re_strcat(
char *_Dest,
char *_Source,
int *destLen,
int *destDim)
744 int srclen = (int) strlen(_Source);
745 *destLen = *destLen + srclen;
746 if(*destLen > *destDim -1)
748 *destDim = *destDim + srclen + 1 + 100;
749 _Dest = REALLOC(_Dest,*destDim);
751 _Dest = strcat(_Dest,_Source);
764 void InitScriptField(
int num, indexT kind, indexT type,
const char* field,
union anyVrml value) {
766 char *smallfield = NULL;
774 int rowCount, eleCount;
783 float defaultFloat[] = {0.0f,0.0f,0.0f,0.0f};
784 int defaultInt[] = {0,0,0,0};
785 double defaultDouble[] = {0.0, 0.0, 0.0, 0.0};
787 struct X3D_Node *defaultVoid[] = {NULL,NULL};
790 #ifdef JAVASCRIPTVERBOSE
791 printf (
"calling InitScriptField from thread %u\n",pthread_self());
792 printf (
"\nInitScriptField, num %d, kind %s type %s field %s value %d\n", num,PROTOKEYWORDS[kind],FIELDTYPES[type],field,value);
795 if ((kind != PKW_inputOnly) && (kind != PKW_outputOnly) && (kind != PKW_initializeOnly) && (kind != PKW_inputOutput)) {
796 ConsoleMessage (
"InitScriptField: invalid kind for script: %d\n",kind);
800 if (type >= FIELDTYPES_COUNT) {
801 ConsoleMessage (
"InitScriptField: invalid type for script: %d\n",type);
806 if (kind == PKW_inputOnly) {
807 sprintf (mynewname,
"__eventIn_Value_%s",field);
808 }
else strcpy(mynewname,field);
813 case FIELDTYPE_SFBool:
814 case FIELDTYPE_SFFloat:
815 case FIELDTYPE_SFTime:
816 case FIELDTYPE_SFDouble:
817 case FIELDTYPE_SFInt32:
818 case FIELDTYPE_SFString: {
820 if (kind != PKW_inputOnly) {
821 JSaddGlobalECMANativeProperty(num, field);
822 if (kind == PKW_initializeOnly || kind == PKW_inputOutput) {
823 if (type == FIELDTYPE_SFString) {
824 tlen = (int) strlen(value.sfstring->strptr) + strlen(field) + 20;
826 tlen = (int) strlen(field) + 400;
828 smallfield = MALLOC (
char *, tlen);
829 smallfield[0] =
'\0';
832 case FIELDTYPE_SFFloat: sprintf (smallfield,
"%s=%f\n",field,value.sffloat);
break;
833 case FIELDTYPE_SFTime: sprintf (smallfield,
"%s=%f\n",field,value.sftime);
break;
834 case FIELDTYPE_SFDouble: sprintf (smallfield,
"%s=%f\n",field,value.sftime);
break;
835 case FIELDTYPE_SFInt32: sprintf (smallfield,
"%s=%d\n",field,value.sfint32);
break;
836 case FIELDTYPE_SFBool:
837 if (value.sfbool == 1) sprintf (smallfield,
"%s=true",field);
838 else sprintf (smallfield,
"%s=false",field);
840 case FIELDTYPE_SFString:
841 sprintf (smallfield,
"%s=\"%s\"\n",field,value.sfstring->strptr);
break;
844 if (!ACTUALRUNSCRIPT(num,smallfield,&rval))
845 printf (
"huh??? Field initialization script failed %s\n",smallfield);
857 case FIELDTYPE_MFString:
858 case FIELDTYPE_MFTime:
859 case FIELDTYPE_MFBool:
860 case FIELDTYPE_MFInt32:
861 case FIELDTYPE_MFFloat:
862 JSaddGlobalECMANativeProperty(num, field);
863 MFhasECMAtype = TRUE;
866 MFhasECMAtype = FALSE;
876 if (kind == PKW_initializeOnly || kind == PKW_inputOutput) {
881 case FIELDTYPE_SFNode:
882 VoidPtr = (
struct X3D_Node **) (&(value.sfnode)); elements = 1;
884 case FIELDTYPE_MFColor:
885 FloatPtr = (
float *) value.mfcolor.p; elements = value.mfcolor.n;
887 case FIELDTYPE_MFColorRGBA:
888 FloatPtr = (
float *) value.mfcolorrgba.p; elements = value.mfcolorrgba.n;
890 case FIELDTYPE_MFVec2f:
891 FloatPtr = (
float *) value.mfvec2f.p; elements = value.mfvec2f.n;
893 case FIELDTYPE_MFVec3f:
894 FloatPtr = (
float *) value.mfvec3f.p; elements = value.mfvec3f.n;
896 case FIELDTYPE_MFRotation:
897 FloatPtr = (
float *) value.mfrotation.p; elements = value.mfrotation.n;
899 case FIELDTYPE_SFVec2f:
900 FloatPtr = (
float *) value.sfvec2f.c; elements = 1;
902 case FIELDTYPE_SFColor:
903 FloatPtr = value.sfcolor.c; elements = 1;
905 case FIELDTYPE_SFColorRGBA:
906 FloatPtr = value.sfcolorrgba.c; elements = 1;
908 case FIELDTYPE_SFRotation:
909 FloatPtr = value.sfrotation.c; elements = 1;
911 case FIELDTYPE_SFVec3f:
912 FloatPtr = value.sfvec3f.c; elements =1;
914 case FIELDTYPE_SFVec3d:
915 DoublePtr = value.sfvec3d.c; elements =1;
917 case FIELDTYPE_MFString:
918 SVPtr = value.mfstring.p; elements = value.mfstring.n;
920 case FIELDTYPE_MFTime:
921 DoublePtr = value.mftime.p; elements = value.mftime.n;
923 case FIELDTYPE_MFBool:
924 IntPtr = value.mfbool.p; elements = value.mfbool.n;
926 case FIELDTYPE_SFImage:
927 case FIELDTYPE_MFInt32:
928 IntPtr = value.mfint32.p; elements = value.mfint32.n;
930 case FIELDTYPE_MFNode:
931 VoidPtr = (
struct X3D_Node **)(value.mfnode.p); elements = value.mfnode.n;
933 case FIELDTYPE_MFFloat:
934 FloatPtr = value.mffloat.p; elements = value.mffloat.n;
936 case FIELDTYPE_SFVec4f:
937 FloatPtr = value.sfvec4f.c; elements = 1;
939 case FIELDTYPE_SFVec4d:
940 DoublePtr = value.sfvec4d.c; elements = 1;
944 printf (
"unhandled type, in InitScriptField %d\n",type);
954 case FIELDTYPE_SFNode:
955 case FIELDTYPE_MFNode:
956 VoidPtr = (
struct X3D_Node **) &defaultVoid;
960 case FIELDTYPE_MFColor:
961 case FIELDTYPE_MFColorRGBA:
962 case FIELDTYPE_MFVec2f:
963 case FIELDTYPE_MFVec3f:
964 case FIELDTYPE_MFRotation:
965 case FIELDTYPE_SFVec2f:
966 case FIELDTYPE_SFColor:
967 case FIELDTYPE_SFColorRGBA:
968 case FIELDTYPE_SFRotation:
969 case FIELDTYPE_SFVec3f:
970 case FIELDTYPE_SFVec4f:
971 case FIELDTYPE_MFFloat:
972 FloatPtr = defaultFloat;
976 case FIELDTYPE_MFBool:
977 case FIELDTYPE_MFInt32:
982 case FIELDTYPE_SFString:
983 case FIELDTYPE_MFString:
984 sptr[0] = newASCIIString(
"");
989 case FIELDTYPE_SFImage:
994 case FIELDTYPE_SFVec2d:
995 case FIELDTYPE_SFVec3d:
996 case FIELDTYPE_MFTime:
997 case FIELDTYPE_SFTime:
998 case FIELDTYPE_SFDouble:
999 case FIELDTYPE_SFVec4d:
1000 DoublePtr = defaultDouble;
1004 printf (
"unhandled type, in InitScriptField part 2 %d\n",type);
1011 rows = returnElementRowSize (type);
1013 #ifdef JAVASCRIPTVERBOSE
1014 printf (
"in fieldSet, we have ElementRowSize %d and individual elements %d\n",rows,elements);
1041 int dstlen, dstdim, tdim;
1043 thisValue = MALLOC(
char *, tdim+1);
1044 dstdim = (rows+1)*(elements*15) + 100;
1046 smallfield = MALLOC (
char *, dstdim+1);
1048 if (type != convertToSFType(type)) haveMulti = TRUE;
1049 else haveMulti = FALSE;
1052 sftype = STRDUP((
char *)FIELDTYPES[convertToSFType(type)]);
1055 if (strncmp(sftype,
"SFString",8)==0) strcpy (sftype,
"String");
1059 smallfield[0] =
'\0';
1063 smallfield = re_strcat(smallfield,
"new ",&dstlen,&dstdim);
1064 smallfield = re_strcat(smallfield, (
char *)FIELDTYPES[type],&dstlen,&dstdim);
1065 smallfield = re_strcat(smallfield,
"(",&dstlen,&dstdim);
1069 for (eleCount=0; eleCount<elements; eleCount++) {
1071 if (!MFhasECMAtype) {
1072 smallfield = re_strcat(smallfield,
"new ",&dstlen,&dstdim);
1073 smallfield = re_strcat(smallfield, sftype,&dstlen,&dstdim);
1074 smallfield = re_strcat(smallfield,
"(",&dstlen,&dstdim);
1078 for (rowCount=0; rowCount<rows; rowCount++ ) {
1079 if (IntPtr != NULL) {
1080 sprintf (thisValue,
"%d",*IntPtr); IntPtr++;
1081 }
else if (FloatPtr != NULL) {
1082 sprintf (thisValue,
"%f",*FloatPtr); FloatPtr++;
1083 }
else if (DoublePtr != NULL) {
1084 sprintf (thisValue,
"%f",*DoublePtr); DoublePtr++;
1085 }
else if (SVPtr != NULL) {
1086 sptr[0] = *SVPtr; SVPtr++;
1087 if((
int)strlen(sptr[0]->strptr)+2 > tdim-1)
1089 tdim = (int) strlen(sptr[0]->strptr) + 1 + 100;
1090 thisValue = REALLOC(thisValue,tdim);
1092 sprintf (thisValue,
"\"%s\"",sptr[0]->strptr);
1096 sprintf (thisValue,
"\"%p\"", VoidPtr[0]); VoidPtr++;
1098 smallfield = re_strcat(smallfield, thisValue,&dstlen,&dstdim);
1099 if (rowCount < (rows-1)) smallfield = re_strcat(smallfield,
",",&dstlen,&dstdim);
1102 if (!MFhasECMAtype) smallfield = re_strcat(smallfield,
")",&dstlen,&dstdim);
1103 if (eleCount < (elements-1)) smallfield = re_strcat(smallfield,
",",&dstlen,&dstdim);
1109 smallfield = re_strcat(smallfield,
")",&dstlen,&dstdim);
1112 FREE_IF_NZ (thisValue);
1115 #ifdef JAVASCRIPTVERBOSE
1116 printf (
"JScript, for non-ECMA newname %s, sending :%s:\n",mynewname,smallfield);
1119 JSaddGlobalAssignProperty (num,mynewname,smallfield);
1126 if (kind == PKW_outputOnly) {
1133 fptr = JSparamIndex (field, FIELDTYPES[type]);
1136 touched = get_valueChanged_flag (fptr, num);
1139 resetScriptTouchedFlag(num, fptr);
1141 ScriptControl = getScriptControlIndex(num);
1142 #if defined(JS_THREADSAFE)
1143 JS_BeginRequest(ScriptControl->cx);
1145 CLEANUP_JAVASCRIPT(ScriptControl->cx)
1146 #if defined(JS_THREADSAFE)
1147 JS_EndRequest(ScriptControl->cx);
1150 FREE_IF_NZ (smallfield);
1151 FREE_IF_NZ (sftype);
1153 #ifdef JAVASCRIPTVERBOSE
1154 printf (
"finished InitScriptField\n");
1158 static int JSaddGlobalECMANativeProperty(
int num,
const char *name) {
1159 JSContext *_context;
1160 JSObject *_globalObj;
1161 jsval rval = INT_TO_JSVAL(0);
1164 ScriptControl = getScriptControlIndex(num);
1166 _context = (JSContext*)ScriptControl->cx;
1167 _globalObj = (JSObject*)ScriptControl->glob;
1169 #ifdef JAVASCRIPTVERBOSE
1170 printf(
"addGlobalECMANativeProperty: name \"%s\"\n", name);
1173 #if defined(JS_THREADSAFE)
1174 JS_BeginRequest(_context);
1181 if (!JS_DefineProperty(_context, _globalObj, name, rval, NULL, setECMANative,
1182 #
if JS_VERSION < 185
1183 0 | JSPROP_PERMANENT
1188 printf(
"JS_DefineProperty failed for \"%s\" in addGlobalECMANativeProperty.\n", name);
1189 #if defined(JS_THREADSAFE)
1190 JS_EndRequest(_context);
1193 #if defined(JS_THREADSAFE)
1195 JS_EndRequest(_context);
1202 static int JSaddGlobalAssignProperty(
int num,
const char *name,
const char *str) {
1203 jsval _rval = INT_TO_JSVAL(0);
1204 JSContext *_context;
1205 JSObject *_globalObj;
1208 ScriptControl = getScriptControlIndex(num);
1211 _context = (JSContext*)ScriptControl->cx;
1212 _globalObj = (JSObject*)ScriptControl->glob;
1214 #ifdef JAVASCRIPTVERBOSE
1215 printf(
"addGlobalAssignProperty: cx: %p obj %p name \"%s\", evaluate script \"%s\"\n",
1216 _context, _globalObj, name, str);
1219 #if defined(JS_THREADSAFE)
1220 JS_BeginRequest(_context);
1222 if (!JS_EvaluateScript(_context, _globalObj, str, (
int) strlen(str), FNAME_STUB, LINENO_STUB, &_rval)) {
1223 ConsoleMessage (
"JSaddGlobalAssignProperty - JS_EvaluateScript failed for %s", str);
1224 #if defined(JS_THREADSAFE)
1225 JS_EndRequest(_context);
1228 #if defined(JS_THREADSAFE)
1230 JS_EndRequest(_context);
1233 #if defined(JS_THREADSAFE)
1234 JS_BeginRequest(_context);
1236 if (!JS_DefineProperty(_context, _globalObj, name, _rval, getAssignProperty, setAssignProperty, 0 | JSPROP_PERMANENT)) {
1237 printf(
"JS_DefineProperty failed for \"%s\" in addGlobalAssignProperty.\n", name);
1238 #if defined(JS_THREADSAFE)
1239 JS_EndRequest(_context);
1242 #if defined(JS_THREADSAFE)
1244 JS_EndRequest(_context);
1253 #if defined(JS_THREADSAFE)
1254 # define JSBEGINREQUEST_SUBSTITUTION(mycx) JS_BeginRequest(mycx);
1255 # define JSENDREQUEST_SUBSTITUTION(mycx) JS_EndRequest(mycx);
1257 # define JSBEGINREQUEST_SUBSTITUTION(mycx)
1258 # define JSENDREQUEST_SUBSTITUTION(mycx)
1263 #define GETJSPTR_TYPE_A(thistype) \
1264 case FIELDTYPE_##thistype: { \
1265 thistype##Native *ptr; \
1267 if ((ptr = (thistype##Native *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(*(jsval *)(tg->JScript.JSglobal_return_val)))) == NULL) { \
1268 printf( "JS_GetPrivate failed in get_valueChanged_flag\n"); \
1269 JSENDREQUEST_SUBSTITUTION(cx) \
1273 tg->CRoutes.JSSFpointer = (void *)ptr; \
1274 touched = ptr->valueChanged; \
1278 #define RESET_TOUCHED_TYPE_A(thistype) \
1279 case FIELDTYPE_##thistype: { \
1280 ((thistype##Native *)tg->CRoutes.JSSFpointer)->valueChanged = 0; \
1284 #define GETJSPTR_TYPE_MF_A(thisMFtype,thisSFtype) \
1285 case FIELDTYPE_##thisMFtype: { \
1286 thisSFtype##Native *ptr; \
1287 jsval mainElement; \
1290 if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(*(jsval *)(tg->JScript.JSglobal_return_val)), "length", &mainElement)) { \
1291 printf ("JS_GetProperty failed for \"length\" in get_valueChanged_flag\n"); \
1292 JSENDREQUEST_SUBSTITUTION(cx) \
1295 len = JSVAL_TO_INT(mainElement); \
1297 for (i = 0; i < len; i++) { \
1298 if (!JS_GetElement(cx, JSVAL_TO_OBJECT(*(jsval*)(tg->JScript.JSglobal_return_val)), i, &mainElement)) { \
1299 printf ("JS_GetElement failed for %d in get_valueChanged_flag\n",i); \
1300 JSENDREQUEST_SUBSTITUTION(cx) \
1303 if ((ptr = (thisSFtype##Native *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(mainElement))) == NULL) { \
1304 printf( "JS_GetPrivate failed for obj in setField_javascriptEventOut.\n"); \
1305 JSENDREQUEST_SUBSTITUTION(cx) \
1308 if (ptr->valueChanged > 0) touched = TRUE; \
1314 #define RESET_TOUCHED_TYPE_MF_A(thisMFtype,thisSFtype) \
1315 case FIELDTYPE_##thisMFtype: { \
1316 thisSFtype##Native *ptr; \
1317 jsval mainElement; \
1321 cx = scriptcontrol->cx; \
1322 JSBEGINREQUEST_SUBSTITUTION(cx) \
1323 if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(*(jsval*)(tg->JScript.JSglobal_return_val)), "length", &mainElement)) { \
1324 printf ("JS_GetProperty failed for \"length\" in get_valueChanged_flag\n"); \
1325 JSENDREQUEST_SUBSTITUTION(cx) \
1328 len = JSVAL_TO_INT(mainElement); \
1330 for (i = 0; i < len; i++) { \
1331 if (!JS_GetElement(cx, JSVAL_TO_OBJECT(*(jsval*)(tg->JScript.JSglobal_return_val)), i, &mainElement)) { \
1332 printf ("JS_GetElement failed for %d in get_valueChanged_flag\n",i); \
1333 JSENDREQUEST_SUBSTITUTION(cx) \
1336 if ((ptr = (thisSFtype##Native *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(mainElement))) == NULL) { \
1337 printf( "JS_GetPrivate failed for obj in setField_javascriptEventOut.\n"); \
1338 JSENDREQUEST_SUBSTITUTION(cx) \
1341 ptr->valueChanged = 0; \
1343 JSENDREQUEST_SUBSTITUTION(cx) \
1351 OLDCODE #define savedBool Bool
1359 #define GET_ECMA_TOUCHED(thistype) \
1360 case FIELDTYPE_SF##thistype: { \
1361 touched = findNameInECMATable( scriptcontrol->cx,fullname);\
1365 #define GET_ECMA_MF_TOUCHED(thistype) \
1366 case FIELDTYPE_MF##thistype: {\
1367 jsval mainElement; \
1369 if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(*(jsval*)(tg->JScript.JSglobal_return_val)), "MF_ECMA_has_changed", &mainElement)) { \
1370 printf ("JS_GetProperty failed for \"MF_ECMA_HAS_changed\" in get_valueChanged_flag\n"); \
1372 touched = JSVAL_TO_INT(mainElement);\
1376 #define RESET_ECMA_MF_TOUCHED(thistype) \
1377 case FIELDTYPE_##thistype: {\
1378 jsval myv = INT_TO_JSVAL(0); \
1380 JSBEGINREQUEST_SUBSTITUTION(scriptcontrol->cx) \
1381 if (!JS_SetProperty(scriptcontrol->cx, JSVAL_TO_OBJECT(*(jsval*)(tg->JScript.JSglobal_return_val)), "MF_ECMA_has_changed", &myv)) { \
1382 printf( "JS_SetProperty failed for \"MF_ECMA_has_changed\" in RESET_ECMA_MF_TOUCHED.\n"); \
1388 JSENDREQUEST_SUBSTITUTION(scriptcontrol->cx) \
1392 #define RESET_TOUCHED_TYPE_ECMA(thistype) \
1393 case FIELDTYPE_##thistype: { \
1394 JSBEGINREQUEST_SUBSTITUTION(scriptcontrol->cx) \
1395 resetNameInECMATable( scriptcontrol->cx,JSparamnames[fptr].name); \
1396 JSENDREQUEST_SUBSTITUTION(scriptcontrol->cx) \
1402 OLDCODE #define Bool savedBool
1454 int get_valueChanged_flag (
int fptr,
int actualscript) {
1459 JSObject *interpobj;
1468 scriptcontrol = getScriptControlIndex(actualscript);
1469 interpobj = (JSObject*)scriptcontrol->glob;
1470 cx = (JSContext*)scriptcontrol->cx;
1471 fullname = JSparamnames[fptr].name;
1473 #if defined(JS_THREADSAFE)
1474 JS_BeginRequest(cx);
1477 printf (
"\ngetting property for fullname %s, cx %p, interpobj %d script %d, fptr %d (%s:%s)\n",
1478 fullname,cx,interpobj,actualscript, fptr,
1479 JSparamnames[fptr].name, FIELDTYPES[JSparamnames[fptr].type]);
1482 if (!JS_GetProperty(cx, interpobj ,fullname,tg->JScript.JSglobal_return_val)) {
1483 printf (
"cant get property for %s\n",fullname);
1484 #if defined(JS_THREADSAFE)
1490 printf (
"so, property is %d (%p)\n",*(jsval*)tg->JScript.JSglobal_return_val,*(jsval *)tg->JScript.JSglobal_return_val);
1491 printf(
"get_valueChanged_flag: node type: %s name %s\n",FIELDTYPES[JSparamnames[fptr].type],JSparamnames[fptr].name);
1494 switch (JSparamnames[fptr].type) {
1496 GETJSPTR_TYPE_A(SFNode)
1503 GETJSPTR_TYPE_A(SFImage)
1508 GETJSPTR_TYPE_MF_A(MFNode,SFNode)
1509 GETJSPTR_TYPE_MF_A(MFVec2f,
SFVec2f)
1510 GETJSPTR_TYPE_MF_A(MFVec3f,
SFVec3f)
1511 GETJSPTR_TYPE_MF_A(MFVec4f,
SFVec4f)
1512 GETJSPTR_TYPE_MF_A(MFVec4d,
SFVec4d)
1514 GETJSPTR_TYPE_MF_A(MFColor,
SFColor)
1517 GET_ECMA_MF_TOUCHED(Int32)
1518 GET_ECMA_MF_TOUCHED(Bool)
1519 GET_ECMA_MF_TOUCHED(Time)
1520 GET_ECMA_MF_TOUCHED(Double)
1521 GET_ECMA_MF_TOUCHED(Float)
1522 GET_ECMA_MF_TOUCHED(String)
1524 GET_ECMA_TOUCHED(Int32)
1525 GET_ECMA_TOUCHED(Bool)
1526 GET_ECMA_TOUCHED(Float)
1527 GET_ECMA_TOUCHED(Time)
1528 GET_ECMA_TOUCHED(Double)
1529 GET_ECMA_TOUCHED(String)
1531 default: {printf (
"not handled yet in get_valueChanged_flag %s\n",FIELDTYPES[JSparamnames[fptr].type]);
1534 #if defined(JS_THREADSAFE)
1540 if (JSparamnames[fptr].type == FIELDTYPE_MFString) {
1545 unsigned CRCCheck = 0;
1546 cx = p->ScriptControl[actualscript].cx;
1547 #if defined(JS_THREADSAFE)
1548 JS_BeginRequest(cx);
1550 if (!JS_GetProperty(cx, JSglobal_return_val,
"length", &mainElement)) {
1551 printf (
"JS_GetProperty failed for length_flag\n");
1553 len = JSVAL_TO_INT(mainElement);
1555 for (i = 0; i < len; i++) {
1556 if (!JS_GetElement(cx, JSglobal_return_val, i, &mainElement)) {
1557 printf (
"JS_GetElement failed for %d in get_valueChanged_flag\n",i);
1560 CRCCheck += (unsigned) mainElement;
1571 printf (
"CRCcheck %u\n",CRCCheck);
1572 #if defined(JS_THREADSAFE)
1586 void resetScriptTouchedFlag(
int actualscript,
int fptr) {
1593 printf (
"resetScriptTouchedFlag, name %s type %s script %d, fptr %d\n",JSparamnames[fptr].name, stringFieldtypeType(JSparamnames[fptr].type), actualscript, fptr);
1595 scriptcontrol = getScriptControlIndex(actualscript);
1596 switch (JSparamnames[fptr].type) {
1598 RESET_TOUCHED_TYPE_A(SFNode)
1605 RESET_TOUCHED_TYPE_A(SFImage)
1608 RESET_TOUCHED_TYPE_MF_A(MFRotation,
SFRotation)
1609 RESET_TOUCHED_TYPE_MF_A(MFNode,SFNode)
1610 RESET_TOUCHED_TYPE_MF_A(MFVec2f,
SFVec2f)
1611 RESET_TOUCHED_TYPE_MF_A(MFVec3f,
SFVec3f)
1612 RESET_TOUCHED_TYPE_MF_A(MFVec4f,
SFVec4f)
1613 RESET_TOUCHED_TYPE_MF_A(MFVec4d,
SFVec4d)
1615 RESET_TOUCHED_TYPE_MF_A(MFColor,
SFColor)
1618 RESET_TOUCHED_TYPE_ECMA (SFInt32)
1619 RESET_TOUCHED_TYPE_ECMA (SFBool)
1620 RESET_TOUCHED_TYPE_ECMA (SFFloat)
1621 RESET_TOUCHED_TYPE_ECMA (SFTime)
1622 RESET_TOUCHED_TYPE_ECMA (SFDouble)
1623 RESET_TOUCHED_TYPE_ECMA (SFString)
1624 RESET_ECMA_MF_TOUCHED(MFInt32)
1625 RESET_ECMA_MF_TOUCHED(MFBool)
1626 RESET_ECMA_MF_TOUCHED(MFFloat)
1627 RESET_ECMA_MF_TOUCHED(MFTime)
1628 RESET_ECMA_MF_TOUCHED(MFString)
1631 default: {printf (
"can not reset touched_flag for %s\n",stringFieldtypeType(JSparamnames[fptr].type));
1638 int jsActualrunScript(
int num,
char *script);
1639 void JSInitializeScriptAndFields (
int num) {
1662 thisEntry = ScriptControl[num].paramList;
1663 while (thisEntry != NULL) {
1665 InitScriptField(num, thisEntry->kind, thisEntry->type, thisEntry->field, thisEntry->value);
1668 nextEntry = thisEntry->next;
1669 FREE_IF_NZ (thisEntry->field);
1670 FREE_IF_NZ (thisEntry);
1671 thisEntry = nextEntry;
1675 ScriptControl[num].paramList = NULL;
1677 int i,nfields,kind,itype;
1678 const char *fieldname;
1682 ScriptControl = getScriptControlIndex(num);
1683 script = ScriptControl->script;
1685 nfields = Shader_Script_getScriptFieldCount(script);
1686 for(i=0;i<nfields;i++){
1687 field = Shader_Script_getScriptField(script,i);
1688 fieldname = ScriptFieldDecl_getName(field);
1689 kind = ScriptFieldDecl_getMode(field);
1690 itype = ScriptFieldDecl_getType(field);
1691 InitScriptField(num, kind, itype, fieldname, field->value);
1695 if (!jsActualrunScript(num, ScriptControl->scriptText)) {
1696 ConsoleMessage (
"JSInitializeScriptAndFields, script failure\n");
1697 ScriptControl->scriptOK = FALSE;
1698 ScriptControl->_initialized = TRUE;
1701 FREE_IF_NZ(ScriptControl->scriptText);
1702 ScriptControl->_initialized = TRUE;
1703 ScriptControl->scriptOK = TRUE;
1710 void SaveScriptField (
int num, indexT kind, indexT type,
const char* field,
union anyVrml value) {
1725 nextInsert = &(ScriptControl[num].paramList);
1726 while (*nextInsert != NULL) {
1727 nextInsert = &(*nextInsert)->next;
1732 *nextInsert = newEntry;
1735 newEntry->next = NULL;
1736 newEntry->kind = kind;
1737 newEntry->type = type;
1738 newEntry->field = STRDUP(field);
1739 newEntry->value = value;
1756 void getJSMultiNumType (JSContext *cx,
struct Multi_Vec3f *tn,
int eletype) {
1767 #if JS_VERSION >= 185
1780 elesize = returnElementLength(eletype) * returnElementRowSize(eletype);
1784 #ifdef SETFIELDVERBOSE
1785 printf (
"getJSMultiNumType, JSCreate_global_return_val %u, JSglobal_return_val %u\n",
1786 (
unsigned int) JSVAL_TO_INT(*(jsval *)tg->jsVRMLBrowser.JSCreate_global_return_val),
1787 (
unsigned int) JSVAL_TO_INT(*(jsval *)tg->JScript.JSglobal_return_val));
1790 if (JSVAL_TO_INT(*(jsval*)(tg->jsVRMLBrowser.JSCreate_global_return_val)) != 0) {
1791 myJSVal = (jsval *)tg->jsVRMLBrowser.JSCreate_global_return_val;
1792 *(jsval *)(tg->jsVRMLBrowser.JSCreate_global_return_val) = INT_TO_JSVAL(0);
1794 #ifdef SETFIELDVERBOSE
1795 printf (
"getJSMultiNumType: using JSCreate_global_return_val\n");
1798 #ifdef SETFIELDVERBOSE
1799 printf (
"getJSMultiNumType: using JSglobal_return_val\n");
1802 myJSVal = tg->JScript.JSglobal_return_val;
1805 if (!JSVAL_IS_OBJECT(*myJSVal)) {
1806 printf (
"getJSMultiNumType - did not get an object\n");
1810 #ifdef SETFIELDVERBOSE
1811 printf (
"getJSMultiNumType, tn %p dest has %s size %d\n",tn,stringFieldtypeType(eletype), elesize);
1813 printf(
"getJSMulitNumType, node type of myJSVal is :");
1814 printJSNodeType (cx,myJSVal);
1817 if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(*myJSVal), MF_LENGTH_FIELD, &mainElement)) {
1818 printf (
"JS_GetProperty failed for \"%s\" in getJSMultiNumType\n", MF_LENGTH_FIELD);
1821 len = JSVAL_TO_INT(mainElement);
1822 #ifdef SETFIELDVERBOSE
1823 printf (
"getmuiltie length of grv is %d old len is %d\n",len,tn->n);
1833 tn->p = MALLOC (
struct SFVec3f *, (
unsigned)(elesize*len));
1835 #ifdef SETFIELDVERBOSE
1836 printf (
"MALLOCing memory for elesize %d len %d new pointer now is %p\n",elesize,len,tn->p);
1840 if (eletype == FIELDTYPE_SFString) {
1841 #ifdef SETFIELDVERBOSE
1842 printf (
"getJSMultiNumType, this is a MFString, so making tiny strings for now\n");
1846 for (i=0; i<len; i++) {
1847 *ms = newASCIIString (
"(getJSMultiNumType null)");
1854 fl = (
float *) tn->p;
1856 dl = (
double *) tn->p;
1861 for (i = 0; i < len; i++) {
1862 if (!JS_GetElement(cx, JSVAL_TO_OBJECT(*myJSVal), i, &mainElement)) {
1863 printf (
"WARNING: JS_GetElement failed for %d in getJSMultiNumType\n",i);
1865 case FIELDTYPE_SFNode:
1866 *nl = 0; nl++;
break;
1867 case FIELDTYPE_SFInt32:
1869 case FIELDTYPE_SFDouble:
1870 case FIELDTYPE_SFTime:
1871 *dl=0.0; dl++;
break;
1872 case FIELDTYPE_SFFloat:
1873 *fl = (float) 0.0; fl++;
break;
1874 case FIELDTYPE_SFVec2f:
1875 *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++;
break;
1876 case FIELDTYPE_SFVec3f:
1877 case FIELDTYPE_SFColor:
1878 *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++;
break;
1879 case FIELDTYPE_SFRotation:
1880 *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++;
break;
1881 case FIELDTYPE_SFString:
1882 verify_Uni_String (*ms,
"(empty value)"); ms++;
break;
1884 default : {printf (
"getJSMultiNumType unhandled eletype: %d\n",
1890 #ifdef SETFIELDVERBOSE
1893 _tmpStr = JS_ValueToString(cx, mainElement);
1894 #if JS_VERSION < 185
1895 strp = JS_GetStringBytes(_tmpStr);
1897 strp = strpp = JS_EncodeString(cx,_tmpStr);
1899 printf (
"sub element %d is \"%s\" \n",i,strp);
1900 #if JS_VERSION >= 185
1904 if (JSVAL_IS_OBJECT(mainElement)) printf (
"sub element %d is an OBJECT\n",i);
1905 if (JSVAL_IS_PRIMITIVE(mainElement)) printf (
"sub element %d is an PRIMITIVE\n",i);
1910 case FIELDTYPE_SFNode: {
1912 if (JS_InstanceOf (cx, JSVAL_TO_OBJECT(mainElement), &SFNodeClass, NULL)) {
1916 if ((_vec = (
SFNodeNative *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(mainElement))) == NULL) {
1917 printf (
"error getting native\n");
1925 printf (
"hmm - not an SFNode class\n");
1932 case FIELDTYPE_SFInt32: {
1933 if (!JS_ValueToInt32(cx, mainElement ,il)) {
1940 case FIELDTYPE_SFDouble:
1941 case FIELDTYPE_SFTime: {
1942 if (!JS_ValueToNumber(cx, mainElement ,dl)) *dl=0.0;
1946 case FIELDTYPE_SFFloat: {
1947 if (!JS_ValueToNumber(cx, mainElement, &dtmp)) dtmp=0.0;
1953 case FIELDTYPE_SFVec2f: {
1954 if (JSVAL_IS_OBJECT(mainElement)) {
1955 if ((sfvec2f = (
SFVec2fNative *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(mainElement))) == NULL) {
1956 printf(
"JS_GetPrivate failed for obj in setField_javascriptEventOut.\n");
1959 memcpy ((
void *)fl, (
void *)&(sfvec2f->v),2*
sizeof(
float));
1963 *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++;
1967 case FIELDTYPE_SFVec3f:
1968 case FIELDTYPE_SFColor: {
1969 if (JSVAL_IS_OBJECT(mainElement)) {
1970 if ((sfvec3f = (
SFVec3fNative *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(mainElement))) == NULL) {
1971 printf(
"JS_GetPrivate failed for obj in setField_javascriptEventOut.\n");
1974 memcpy ((
void *)fl, (
void *)&(sfvec3f->v),3*
sizeof(
float));
1978 *fl = (float) 0.0; fl++;
1979 *fl = (float) 0.0; fl++;
1980 *fl = (float) 0.0; fl++;
1984 case FIELDTYPE_SFRotation: {
1985 if (JSVAL_IS_OBJECT(mainElement)) {
1986 if ((sfrotation = (
SFRotationNative *)JS_GetPrivate(cx, JSVAL_TO_OBJECT(mainElement))) == NULL) {
1987 printf(
"JS_GetPrivate failed for obj in setField_javascriptEventOut.\n");
1990 memcpy ((
void *)fl, (
void *)&(sfrotation->v),4*
sizeof(
float));
1994 *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++;
1995 *fl = (float) 0.0; fl++; *fl = (float) 0.0; fl++;
2000 case FIELDTYPE_SFString: {
2003 strval = JS_ValueToString(cx, mainElement);
2004 #if JS_VERSION < 185
2005 strp = JS_GetStringBytes(strval);
2007 strp = strpp = JS_EncodeString(cx,strval);
2011 #ifdef SETFIELDVERBOSE
2012 printf (
"getJSMultiNumType, got string %s\n",strp);
2016 verify_Uni_String (*ms,strp);
2018 #if JS_VERSION >= 185
2024 default : {printf (
"getJSMultiNumType unhandled eletype: %d\n",
2032 #ifdef SETFIELDVERBOSE
2033 printf (
"getJSMultiNumType, setting old length %d to length %d\n",tn->n, len);
2043 void getMFStringtype (JSContext *cx, jsval *from,
struct Multi_String *to) {
2048 char *valStr, *OldvalStr;
2059 if (!JS_ValueToObject(cx, *from, &obj))
2060 printf (
"JS_ValueToObject failed in getMFStringtype\n");
2062 if (!JS_GetProperty(cx, obj, MF_LENGTH_FIELD, &_v)) {
2063 printf (
"JS_GetProperty failed for \"%s\" in getMFStringtype.\n", MF_LENGTH_FIELD);
2066 newlen = JSVAL_TO_INT(_v);
2072 if (newlen > oldlen) {
2075 to->p = MALLOC(
struct Uni_String **, newlen *
sizeof(to->p));
2079 for (count = 0; count <oldlen; count ++) {
2087 for (count = oldlen; count < newlen; count ++) {
2093 *newp = newASCIIString(
"");
2112 for (i = 0; i < newlen; i++) {
2114 OldvalStr = svptr[i]->strptr;
2118 if (!JS_GetElement(cx, obj, i, &_v)) {
2120 "JS_GetElement failed for %d in getMFStringtype\n",i);
2123 strval = JS_ValueToString(cx, _v);
2124 #if JS_VERSION < 185
2125 valStr = JS_GetStringBytes(strval);
2127 valStr = JS_EncodeString(cx,strval);
2133 if (strcmp(valStr,OldvalStr) != 0) {
2135 svptr[i] = newASCIIString(valStr);
2137 #if JS_VERSION >= 185
2154 void setField_javascriptEventOut(
struct X3D_Node *tn,
unsigned int tptr,
int fieldType,
unsigned len,
int extraData, JSContext *scriptContext) {
2161 #if JS_VERSION >= 185
2169 memptr = offsetPointer_deref(
char *, tn, tptr);
2171 #ifdef SETFIELDVERBOSE
2172 strval = JS_ValueToString(scriptContext, *(jsval *)tg->JScript.JSglobal_return_val);
2173 #if JS_VERSION < 185
2174 strp = JS_GetStringBytes(strval);
2176 strp = strpp = JS_EncodeString(scriptContext,strval);
2178 printf (
"start of setField_javascriptEventOut, to %ld:%d = %p, fieldtype %d string %s\n",(
long)tn, tptr, memptr, fieldType, strp);
2179 #if JS_VERSION >= 185
2180 JS_free(scriptContext,strpp);
2184 #define GETJSVAL_TYPE_A(thistype,field) \
2185 case FIELDTYPE_##thistype: { \
2187 memcpy ((void *)memptr, (void *) &(((thistype##Native *)tg->CRoutes.JSSFpointer)->field),len); \
2191 #define GETJSVAL_TYPE_MF_A(MFtype,SFtype) \
2192 case FIELDTYPE_##MFtype: {getJSMultiNumType (scriptContext, (struct Multi_Vec3f *)memptr,FIELDTYPE_##SFtype); break;}
2194 switch (fieldType) {
2207 GETJSVAL_TYPE_MF_A(MFVec2d,
SFVec2d)
2208 GETJSVAL_TYPE_MF_A(MFVec3d,SFVec3d)
2209 GETJSVAL_TYPE_MF_A(MFVec4d,SFVec4d)
2210 GETJSVAL_TYPE_MF_A(MFVec2f,SFVec2f)
2211 GETJSVAL_TYPE_MF_A(MFVec3f,SFVec3f)
2212 GETJSVAL_TYPE_MF_A(MFVec4f,SFVec4f)
2213 GETJSVAL_TYPE_MF_A(MFColor,SFColor)
2214 GETJSVAL_TYPE_MF_A(MFColorRGBA,SFColorRGBA)
2217 case FIELDTYPE_SFInt32:
2218 case FIELDTYPE_SFBool: {
2219 if (!JS_ValueToInt32(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val),&ival)) {
2223 memcpy ((
void *)memptr, (
void *)&ival,len);
2227 case FIELDTYPE_SFDouble:
2228 case FIELDTYPE_SFTime: {
2229 if (!JS_ValueToNumber(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val),&tval)) tval=0.0;
2230 memcpy ((
void *)memptr, (
void *)&tval,len);
2234 case FIELDTYPE_SFFloat: {
2235 if (!JS_ValueToNumber(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val),&tval)) tval=0.0;
2237 fl[0] = (float) tval;
2238 memcpy ((
void *)memptr, (
void *)fl,len);
2242 case FIELDTYPE_SFImage: {
2244 strval = JS_ValueToString(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val));
2245 #if JS_VERSION < 185
2246 strp = JS_GetStringBytes(strval);
2248 strp = strpp = JS_EncodeString(scriptContext,strval);
2251 Parser_scanStringValueToMem(tn, tptr, FIELDTYPE_SFImage, strp, FALSE);
2252 #if JS_VERSION >= 185
2253 JS_free(scriptContext,strpp);
2258 case FIELDTYPE_SFString: {
2262 strval = JS_ValueToString(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val));
2263 #if JS_VERSION < 185
2264 strp = JS_GetStringBytes(strval);
2266 strp = strpp = JS_EncodeString(scriptContext,strval);
2272 newptr = (intptr_t *)memptr;
2274 verify_Uni_String (ms,strp);
2275 #if JS_VERSION >= 185
2276 JS_free(scriptContext,strpp);
2283 case FIELDTYPE_MFFloat: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFFloat);
break;}
2284 case FIELDTYPE_MFInt32: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFInt32);
break;}
2285 case FIELDTYPE_MFTime: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFTime);
break;}
2286 case FIELDTYPE_MFDouble: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFDouble);
break;}
2287 case FIELDTYPE_MFNode: {
2290 strval = JS_ValueToString(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val));
2291 #if JS_VERSION < 185
2292 strp = JS_GetStringBytes(strval);
2294 strp = strpp = JS_EncodeString(scriptContext,strval);
2298 while ((*strp >
'\0') && (*strp <=
' ')) strp ++;
2300 if (*strp ==
'[') strp ++;
2301 while ((*strp >
'\0') && (*strp <=
' ')) strp ++;
2305 mynode = X3D_NODE(atol(strp));
2306 #if JS_VERSION >= 185
2307 JS_free(scriptContext,strpp);
2315 getMFNodetype (mynode,(
struct Multi_Node *)memptr,X3D_NODE(tn),extraData);
break;
2317 case FIELDTYPE_MFString: {
2320 (jsval *)tg->JScript.JSglobal_return_val,
2325 case FIELDTYPE_SFNode: {
2329 memcpy ((
void *)memptr, (
void *) &(((
SFNodeNative *)tg->CRoutes.JSSFpointer)->handle),returnElementLength(FIELDTYPE_SFNode));
2337 default: { printf(
"WARNING: unhandled from type %s\n", stringFieldtypeType(fieldType));
2341 #ifdef SETFIELDVERBOSE
2342 printf (
"done setField_javascriptEventOut\n");
2343 if (fieldType == FIELDTYPE_MFInt32) {
2344 printf (
"setField_javascriptEventOut, checking the pointers...\n");
2345 printf (
"node type is %s\n",stringNodeType(X3D_NODE(tn)->_nodeType));
2347 if (fieldType == FIELDTYPE_SFNode) {
2348 printf (
"setField_javascriptEventOut, checking the pointers...\n");
2349 printf (
"node type is %s\n",stringNodeType(X3D_NODE(tn)->_nodeType));
2355 void Parser_scanStringValueToMem_B(
union anyVrml* any, indexT ctype,
const char *value,
int isXML);
2357 void setField_javascriptEventOut_B(
union anyVrml* any,
2358 int fieldType,
unsigned len,
int extraData, JSContext *scriptContext)
2369 #if JS_VERSION >= 185
2377 memptr = (
char *)any;
2379 #ifdef SETFIELDVERBOSE
2380 strval = JS_ValueToString(scriptContext, *(jsval *)tg->JScript.JSglobal_return_val);
2381 #if JS_VERSION < 185
2382 strp = JS_GetStringBytes(strval);
2384 strp = strpp = JS_EncodeString(scriptContext,strval);
2386 printf (
"start of setField_javascriptEventOut, to %ld:%d = %p, fieldtype %d string %s\n",(
long)any, fieldType, memptr, fieldType, strp);
2387 #if JS_VERSION >= 185
2388 JS_free(scriptContext,strpp);
2392 #define GETJSVAL_TYPE_A(thistype,field) \
2393 case FIELDTYPE_##thistype: { \
2395 memcpy ((void *)memptr, (void *) &(((thistype##Native *)tg->CRoutes.JSSFpointer)->field),len); \
2399 #define GETJSVAL_TYPE_MF_A(MFtype,SFtype) \
2400 case FIELDTYPE_##MFtype: {getJSMultiNumType (scriptContext, (struct Multi_Vec3f *)memptr,FIELDTYPE_##SFtype); break;}
2402 switch (fieldType) {
2406 GETJSVAL_TYPE_A(SFVec3d,v)
2407 GETJSVAL_TYPE_A(SFVec4d,v)
2408 GETJSVAL_TYPE_A(SFVec2f,v)
2409 GETJSVAL_TYPE_A(SFVec3f,v)
2410 GETJSVAL_TYPE_A(SFVec4f,v)
2411 GETJSVAL_TYPE_A(SFColor,v)
2412 GETJSVAL_TYPE_A(SFColorRGBA,v)
2415 GETJSVAL_TYPE_MF_A(MFVec2d,
SFVec2d)
2416 GETJSVAL_TYPE_MF_A(MFVec3d,SFVec3d)
2417 GETJSVAL_TYPE_MF_A(MFVec4d,SFVec4d)
2418 GETJSVAL_TYPE_MF_A(MFVec2f,SFVec2f)
2419 GETJSVAL_TYPE_MF_A(MFVec3f,SFVec3f)
2420 GETJSVAL_TYPE_MF_A(MFVec4f,SFVec4f)
2421 GETJSVAL_TYPE_MF_A(MFColor,SFColor)
2422 GETJSVAL_TYPE_MF_A(MFColorRGBA,SFColorRGBA)
2425 case FIELDTYPE_SFInt32:
2426 case FIELDTYPE_SFBool: {
2427 if (!JS_ValueToInt32(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val),&ival)) {
2431 memcpy ((
void *)memptr, (
void *)&ival,len);
2435 case FIELDTYPE_SFDouble:
2436 case FIELDTYPE_SFTime: {
2437 if (!JS_ValueToNumber(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val),&tval)) tval=0.0;
2438 memcpy ((
void *)memptr, (
void *)&tval,len);
2442 case FIELDTYPE_SFFloat: {
2443 if (!JS_ValueToNumber(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val),&tval)) tval=0.0;
2445 fl[0] = (float) tval;
2446 memcpy ((
void *)memptr, (
void *)fl,len);
2450 case FIELDTYPE_SFImage: {
2452 strval = JS_ValueToString(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val));
2453 #if JS_VERSION < 185
2454 strp = JS_GetStringBytes(strval);
2456 strp = strpp = JS_EncodeString(scriptContext,strval);
2459 Parser_scanStringValueToMem_B(any, FIELDTYPE_SFImage, strp, FALSE);
2460 #if JS_VERSION >= 185
2461 JS_free(scriptContext,strpp);
2466 case FIELDTYPE_SFString: {
2470 strval = JS_ValueToString(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val));
2471 #if JS_VERSION < 185
2472 strp = JS_GetStringBytes(strval);
2474 strp = strpp = JS_EncodeString(scriptContext,strval);
2480 newptr = (intptr_t *)memptr;
2482 verify_Uni_String (ms,strp);
2483 #if JS_VERSION >= 185
2484 JS_free(scriptContext,strpp);
2491 case FIELDTYPE_MFFloat: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFFloat);
break;}
2492 case FIELDTYPE_MFInt32: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFInt32);
break;}
2493 case FIELDTYPE_MFTime: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFTime);
break;}
2494 case FIELDTYPE_MFDouble: {getJSMultiNumType (scriptContext, (
struct Multi_Vec3f *)memptr,FIELDTYPE_SFDouble);
break;}
2495 case FIELDTYPE_MFNode: {
2498 strval = JS_ValueToString(scriptContext, *(jsval*)(tg->JScript.JSglobal_return_val));
2499 #if JS_VERSION < 185
2500 strp = JS_GetStringBytes(strval);
2502 strp = strpp = JS_EncodeString(scriptContext,strval);
2506 while ((*strp >
'\0') && (*strp <=
' ')) strp ++;
2508 if (*strp ==
'[') strp ++;
2509 while ((*strp >
'\0') && (*strp <=
' ')) strp ++;
2513 mynode = X3D_NODE(atol(strp));
2514 #if JS_VERSION >= 185
2515 JS_free(scriptContext,strpp);
2526 any->mfnode.p[0] = mynode;
2530 case FIELDTYPE_MFString: {
2533 (jsval *)tg->JScript.JSglobal_return_val,
2538 case FIELDTYPE_SFNode: {
2542 memcpy ((
void *)memptr, (
void *) &(((
SFNodeNative *)tg->CRoutes.JSSFpointer)->handle),returnElementLength(FIELDTYPE_SFNode));
2550 default: { printf(
"WARNING: unhandled from type %s\n", stringFieldtypeType(fieldType));
2554 #ifdef SETFIELDVERBOSE
2555 printf (
"done setField_javascriptEventOut\n");
2556 if (fieldType == FIELDTYPE_MFInt32) {
2557 printf (
"setField_javascriptEventOut, checking the pointers...\n");
2558 printf (
"node type is %s\n",stringNodeType(X3D_NODE(any)->_nodeType));
2560 if (fieldType == FIELDTYPE_SFNode) {
2561 printf (
"setField_javascriptEventOut, checking the pointers...\n");
2562 printf (
"node type is %s\n",stringNodeType(X3D_NODE(any)->_nodeType));
2568 void js_setField_javascriptEventOut(
struct X3D_Node *tn,
unsigned int tptr,
int fieldType,
unsigned len,
int extraData,
int actualscript) {
2571 scriptcontrol = getScriptControlIndex(actualscript);
2572 #if defined(JS_THREADSAFE)
2573 JS_BeginRequest(scriptcontrol->cx);
2575 setField_javascriptEventOut(tn,tptr,fieldType, len, extraData, scriptcontrol->cx);
2576 #if defined(JS_THREADSAFE)
2577 JS_EndRequest(scriptcontrol->cx);
2581 void js_setField_javascriptEventOut_B(
union anyVrml* any,
int fieldType,
unsigned len,
int extraData,
int actualscript){
2584 scriptcontrol = getScriptControlIndex(actualscript);
2585 #if defined(JS_THREADSAFE)
2586 JS_BeginRequest(scriptcontrol->cx);
2588 setField_javascriptEventOut_B(any,fieldType, len, extraData, scriptcontrol->cx);
2590 #if defined(JS_THREADSAFE)
2591 JS_EndRequest(scriptcontrol->cx);
2598 void set_one_ECMAtype (
int tonode,
int toname,
int dataType,
void *Data,
int datalen) {
2599 char scriptline[100];
2606 #ifdef SETFIELDVERBOSE
2607 printf (
"set_one_ECMAtype, to %d namepointer %d, fieldname %s, datatype %d length %d\n",
2608 tonode,toname,JSparamnames[toname].name,dataType,datalen);
2610 ScriptControl = getScriptControlIndex(tonode);
2612 cx = (JSContext*)ScriptControl->cx;
2613 obj = (JSObject*)ScriptControl->glob;
2615 #if defined(JS_THREADSAFE)
2616 JS_BeginRequest(cx);
2621 X3D_ECMA_TO_JS(cx, Data, datalen, dataType, &newval);
2624 sprintf (scriptline,
"__eventIn_Value_%s", JSparamnames[toname].name);
2626 #ifdef SETFIELDVERBOSE
2627 printf (
"set_one_ECMAtype, calling JS_DefineProperty on name %s obj %u, setting setECMANative, 0 \n",scriptline,obj);
2630 if (!JS_DefineProperty(cx,obj, scriptline, newval, JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_PERMANENT)) {
2631 printf(
"JS_DefineProperty failed for \"ECMA in\" at %s:%d.\n",__FILE__,__LINE__);
2632 #if defined(JS_THREADSAFE)
2639 COMPILE_FUNCTION_IF_NEEDED(toname)
2642 RUN_FUNCTION (toname)
2644 #if defined(JS_THREADSAFE)
2658 void setScriptECMAtype (
int num) {
2664 struct CRStruct *CRoutes = getCRoutes();
2667 fn = offsetPointer_deref(
void *, CRoutes[num].routeFromNode, CRoutes[num].fnptr);
2668 len = CRoutes[num].len;
2670 for (to_counter = 0; to_counter < CRoutes[num].tonode_count; to_counter++) {
2673 to_ptr = &(CRoutes[num].tonodes[to_counter]);
2674 myObj = X3D_SCRIPT(to_ptr->routeToNode)->__scriptObj;
2676 tptr = to_ptr->foffset;
2677 set_one_ECMAtype (myObj->num, tptr, JSparamnames[tptr].type, fn,len);
2683 void set_one_MFElementType(
int tonode,
int toname,
int dataType,
void *Data,
int datalen) {
2688 char scriptline[20000];
2701 ScriptControl = getScriptControlIndex(tonode);
2702 cx = (JSContext*)ScriptControl->cx;
2703 obj = (JSObject*)ScriptControl->glob;
2705 #if defined(JS_THREADSAFE)
2706 JS_BeginRequest(cx);
2713 case FIELDTYPE_MFRotation: {
2714 JSObject *newMFObject;
2715 JSObject *newSFObject;
2717 float *fp, *fp_in=(
float *)Data;
2720 newMFObject = JS_ConstructObject(cx, &MFRotationClass, NULL ,JS_GetParent(cx, obj));
2721 ADD_ROOT (cx, newMFObject)
2724 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
2727 elementlen = (
int) sizeof (
float);
2728 for (x=0; x<datalen; x++) {
2730 newSFObject = JS_ConstructObject(cx,&SFRotationClass,NULL, newMFObject);
2731 if ((SFRPptr = (
SFRotationNative *)JS_GetPrivate(cx, newSFObject)) == NULL) {
2732 ConsoleMessage (
"failure in getting SF class at %s:%d\n",__FILE__,__LINE__);
2733 #if defined(JS_THREADSAFE)
2740 fp = (
float *)fp_in; SFRPptr->v.c[0] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2741 fp = (
float *)fp_in; SFRPptr->v.c[1] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2742 fp = (
float *)fp_in; SFRPptr->v.c[2] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2743 fp = (
float *)fp_in; SFRPptr->v.c[3] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2746 if (!JS_DefineElement(cx, newMFObject, (jsint) x, OBJECT_TO_JSVAL(newSFObject),
2747 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
2748 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
2753 SET_LENGTH (cx,newMFObject,datalen)
2756 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
2759 COMPILE_FUNCTION_IF_NEEDED(toname)
2760 RUN_FUNCTION(toname)
2764 case FIELDTYPE_MFVec3f: {
2765 JSObject *newMFObject;
2766 JSObject *newSFObject;
2768 float *fp, *fp_in=(
float *)Data;
2771 newMFObject = JS_ConstructObject(cx, &MFVec3fClass, NULL ,JS_GetParent(cx, obj));
2772 ADD_ROOT (cx, newMFObject)
2775 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
2778 elementlen = (
int) sizeof (
float);
2779 for (x=0; x<datalen; x++) {
2781 newSFObject = JS_ConstructObject(cx,&SFVec3fClass,NULL, newMFObject);
2782 if ((SFRPptr = (
SFVec3fNative *)JS_GetPrivate(cx, newSFObject)) == NULL) {
2783 ConsoleMessage (
"failure in getting SF class at %s:%d\n",__FILE__,__LINE__);
2784 #if defined(JS_THREADSAFE)
2791 fp = (
float *)fp_in; SFRPptr->v.c[0] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2792 fp = (
float *)fp_in; SFRPptr->v.c[1] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2793 fp = (
float *)fp_in; SFRPptr->v.c[2] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2796 if (!JS_DefineElement(cx, newMFObject, (jsint) x, OBJECT_TO_JSVAL(newSFObject),
2797 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
2798 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
2803 SET_LENGTH (cx,newMFObject,datalen)
2806 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
2809 COMPILE_FUNCTION_IF_NEEDED(toname)
2810 RUN_FUNCTION(toname)
2814 case FIELDTYPE_MFColor: {
2815 JSObject *newMFObject;
2816 JSObject *newSFObject;
2818 float *fp, *fp_in=(
float *)Data;
2821 newMFObject = JS_ConstructObject(cx, &MFColorClass, NULL ,JS_GetParent(cx, obj));
2822 ADD_ROOT (cx, newMFObject)
2825 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
2828 elementlen = (
int) sizeof (
float);
2829 for (x=0; x<datalen; x++) {
2831 newSFObject = JS_ConstructObject(cx,&SFColorClass,NULL, newMFObject);
2832 if ((SFRPptr = (
SFColorNative *)JS_GetPrivate(cx, newSFObject)) == NULL) {
2833 ConsoleMessage (
"failure in getting SF class at %s:%d\n",__FILE__,__LINE__);
2834 #if defined(JS_THREADSAFE)
2841 fp = (
float *)fp_in; SFRPptr->v.c[0] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2842 fp = (
float *)fp_in; SFRPptr->v.c[1] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2843 fp = (
float *)fp_in; SFRPptr->v.c[2] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2846 if (!JS_DefineElement(cx, newMFObject, (jsint) x, OBJECT_TO_JSVAL(newSFObject),
2847 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
2848 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
2853 SET_LENGTH (cx,newMFObject,datalen)
2856 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
2859 COMPILE_FUNCTION_IF_NEEDED(toname)
2860 RUN_FUNCTION(toname)
2864 case FIELDTYPE_MFVec2f: {
2865 JSObject *newMFObject;
2866 JSObject *newSFObject;
2868 float *fp, *fp_in=(
float *)Data;
2871 newMFObject = JS_ConstructObject(cx, &MFVec2fClass, NULL ,JS_GetParent(cx, obj));
2872 ADD_ROOT (cx, newMFObject)
2875 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
2878 elementlen = (
int) sizeof (
float);
2879 for (x=0; x<datalen; x++) {
2881 newSFObject = JS_ConstructObject(cx,&SFVec2fClass,NULL, newMFObject);
2882 if ((SFRPptr = (
SFVec2fNative *)JS_GetPrivate(cx, newSFObject)) == NULL) {
2883 ConsoleMessage (
"failure in getting SF class at %s:%d\n",__FILE__,__LINE__);
2884 #if defined(JS_THREADSAFE)
2891 fp = (
float *)fp_in; SFRPptr->v.c[0] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2892 fp = (
float *)fp_in; SFRPptr->v.c[1] = *fp; fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2895 if (!JS_DefineElement(cx, newMFObject, (jsint) x, OBJECT_TO_JSVAL(newSFObject),
2896 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
2897 ConsoleMessage(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
2902 SET_LENGTH (cx,newMFObject,datalen)
2905 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
2908 COMPILE_FUNCTION_IF_NEEDED(toname)
2909 RUN_FUNCTION(toname)
2914 case FIELDTYPE_MFFloat: {
2915 JSObject *newMFObject;
2917 float *fp, *fp_in=(
float *)Data;
2919 newMFObject = JS_ConstructObject(cx, &MFFloatClass, NULL ,JS_GetParent(cx, obj));
2920 ADD_ROOT (cx, newMFObject)
2923 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
2926 elementlen = (
int) sizeof (
float);
2927 for (x=0; x<datalen; x++) {
2930 fp = (
float *)fp_in;
2931 JS_NewNumberValue(cx,(
double)*fp,&newjsval);
2932 fp_in = offsetPointer_deref(
float *,fp_in,elementlen);
2935 if (!JS_DefineElement(cx, newMFObject, (jsint) x, newjsval,
2936 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
2937 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
2942 SET_LENGTH (cx,newMFObject,datalen)
2945 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
2948 COMPILE_FUNCTION_IF_NEEDED(toname)
2949 RUN_FUNCTION(toname)
2952 case FIELDTYPE_MFTime: {
2953 JSObject *newMFObject;
2955 double *dp, *dp_in=(
double *)Data;
2958 newMFObject = JS_ConstructObject(cx, &MFTimeClass, NULL ,JS_GetParent(cx, obj));
2959 ADD_ROOT (cx, newMFObject)
2962 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
2965 elementlen = (
int) sizeof (
double);
2966 for (x=0; x<datalen; x++) {
2969 dp = (
double *)dp_in;
2970 JS_NewNumberValue(cx,(
double)*dp,&newjsval);
2971 dp_in = offsetPointer_deref(
double *,dp_in,elementlen);
2974 if (!JS_DefineElement(cx, newMFObject, (jsint) x, newjsval,
2975 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
2976 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
2981 SET_LENGTH (cx,newMFObject,datalen)
2984 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
2987 COMPILE_FUNCTION_IF_NEEDED(toname)
2988 RUN_FUNCTION(toname)
2991 case FIELDTYPE_MFInt32: {
2992 JSObject *newMFObject;
2994 int *ip, *ip_in=(
int *)Data;
2997 newMFObject = JS_ConstructObject(cx, &MFInt32Class, NULL ,JS_GetParent(cx, obj));
2998 ADD_ROOT (cx, newMFObject)
3001 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
3004 elementlen = (
int) sizeof (
float);
3005 for (x=0; x<datalen; x++) {
3009 newjsval = INT_TO_JSVAL((
int)ip);
3010 ip_in = offsetPointer_deref(
int *,ip_in,elementlen);
3013 if (!JS_DefineElement(cx, newMFObject, (jsint) x, newjsval,
3014 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
3015 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
3020 SET_LENGTH (cx,newMFObject,datalen)
3023 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
3026 COMPILE_FUNCTION_IF_NEEDED(toname)
3027 RUN_FUNCTION(toname)
3030 case FIELDTYPE_MFString: {
3031 JSObject *newMFObject;
3036 newMFObject = JS_ConstructObject(cx, &MFStringClass, NULL ,JS_GetParent(cx, obj));
3037 ADD_ROOT (cx, newMFObject)
3043 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
3046 for (x=0; x<datalen; x++) {
3049 chptr = uniptr[x]->strptr;
3050 newjsval = STRING_TO_JSVAL( JS_NewStringCopyZ(cx,chptr));
3053 if (!JS_DefineElement(cx, newMFObject, (jsint) x, newjsval,
3054 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
3055 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
3060 SET_LENGTH (cx,newMFObject,datalen)
3063 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
3066 COMPILE_FUNCTION_IF_NEEDED(toname)
3067 RUN_FUNCTION(toname)
3070 case FIELDTYPE_MFNode: {
3071 JSObject *newMFObject;
3073 double *ip, *ip_in=(
double *)Data;
3075 newMFObject = JS_ConstructObject(cx, &MFNodeClass, NULL ,JS_GetParent(cx, obj));
3076 ADD_ROOT (cx, newMFObject)
3079 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
3082 elementlen = (
int) sizeof (
void *);
3083 for (x=0; x<datalen; x++) {
3085 newjsval = INT_TO_JSVAL((
int)ip);
3086 ip_in = offsetPointer_deref(
double *,ip_in,elementlen);
3089 if (!JS_DefineElement(cx, newMFObject, (jsint) x, newjsval,
3090 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
3091 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
3096 SET_LENGTH (cx,newMFObject,datalen)
3099 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
3102 COMPILE_FUNCTION_IF_NEEDED(toname)
3103 RUN_FUNCTION(toname)
3107 case FIELDTYPE_SFImage: {
3108 JSObject *newMFObject;
3110 int *ip_in=(
int *)Data;
3113 newMFObject = JS_ConstructObject(cx, &SFImageClass, NULL ,JS_GetParent(cx, obj));
3114 ADD_ROOT (cx, newMFObject)
3117 DEFINE_LENGTH_NORV(cx,newMFObject,datalen)
3120 for (x=0; x<datalen; x++) {
3121 newjsval = INT_TO_JSVAL(ip_in[x]);
3123 if (!JS_DefineElement(cx, newMFObject, (jsint) x, newjsval,
3124 JS_GET_PROPERTY_STUB, JS_SET_PROPERTY_STUB3, JSPROP_ENUMERATE)) {
3125 printf(
"failure in inserting SF class at %s:%d\n",__FILE__,__LINE__);
3130 SET_LENGTH (cx,newMFObject,datalen)
3133 SET_EVENTIN_VALUE (cx,obj,toname,newMFObject)
3136 COMPILE_FUNCTION_IF_NEEDED(toname)
3137 RUN_FUNCTION(toname)
3143 printf (
"setMFElement, SHOULD NOT DISPLAY THIS\n");
3144 strcat (scriptline,
"(");
3147 #if defined(JS_THREADSAFE)
3163 void **getInternalDataPointerForJavascriptObject(JSContext *cx, JSObject *obj,
int tnfield) {
3164 char scriptline[100];
3173 sprintf (scriptline,
"__eventIn_Value_%s", JSparamnames[tnfield].name);
3174 #ifdef SETFIELDVERBOSE
3175 printf (
"getInternalDataPointerForJavascriptObject: line %s\n",scriptline);
3178 if (!JS_GetProperty(cx,obj,scriptline,&retval))
3179 printf (
"JS_GetProperty failed in set_one_MultiElementType.\n");
3181 if (!JSVAL_IS_OBJECT(retval))
3182 printf (
"set_one_MultiElementType - not an object\n");
3184 sfObj = JSVAL_TO_OBJECT(retval);
3186 if ((_privPtr = JS_GetPrivate(cx, sfObj)) == NULL)
3187 printf(
"JS_GetPrivate failed set_one_MultiElementType.\n");
3189 if (_privPtr == NULL)
return NULL;
3196 if (JS_InstanceOf(cx, sfObj, &SFVec3fClass, NULL)) {
3198 return (
void **) &me->v;
3200 }
else if (JS_InstanceOf(cx, sfObj, &SFVec3dClass, NULL)) {
3202 return (
void **) &me->v;
3204 }
else if (JS_InstanceOf(cx, sfObj, &SFRotationClass, NULL)) {
3206 return (
void **) &me->v;
3208 }
else if (JS_InstanceOf(cx, sfObj, &SFVec2fClass, NULL)) {
3210 return (
void **) &me->v;
3212 }
else if (JS_InstanceOf(cx, sfObj, &SFColorClass, NULL)) {
3214 return (
void **) &me->v;
3216 }
else if (JS_InstanceOf(cx, sfObj, &SFColorRGBAClass, NULL)) {
3218 return (
void **) &me->v;
3220 }
else if (JS_InstanceOf(cx, sfObj, &SFVec4fClass, NULL)) {
3222 return (
void **) &me->v;
3224 }
else if (JS_InstanceOf(cx, sfObj, &SFVec4dClass, NULL)) {
3226 return (
void **) &me->v;
3228 }
else if (JS_InstanceOf(cx, sfObj, &SFNodeClass, NULL)) {
3230 return (
void **) &me->handle;;
3233 }
else if (JS_InstanceOf(cx, sfObj, &SFImageClass, NULL)) {
3239 ConsoleMessage (
"getInternalDataPointerForJavascriptObject malfunction");
3247 void set_one_MultiElementType (
int tonode,
int tnfield,
void *Data,
int dataLen ) {
3248 char scriptline[100];
3256 ScriptControl = getScriptControlIndex(tonode);
3257 cx = (JSContext*)ScriptControl->cx;
3258 obj = (JSObject*)ScriptControl->glob;
3260 #if defined(JS_THREADSAFE)
3261 JS_BeginRequest(cx);
3267 pp = getInternalDataPointerForJavascriptObject(cx,obj,tnfield);
3270 memcpy (pp,Data, dataLen);
3276 COMPILE_FUNCTION_IF_NEEDED(tnfield)
3279 #ifdef SETFIELDVERBOSE
3280 printf (
"set_one_MultiElementType: running script %s\n",scriptline);
3283 RUN_FUNCTION (tnfield)
3285 #if defined(JS_THREADSAFE)
3290 int runQueuedDirectOutputs(){