Changeset 14591 for trunk/FACT++
- Timestamp:
- 11/08/12 17:09:50 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14579 r14591 397 397 Handle<Value> InterpreterV8::FuncDbQuery(const Arguments &args) 398 398 { 399 if (args.Length()!=1) 400 return ThrowException(String::New("Number of arguments must be exactly 1.")); 401 402 if (!args[0]->IsString()) 403 return ThrowException(String::New("Both arguments must be a string.")); 399 if (args.Length()==0) 400 return ThrowException(String::New("Arguments expected.")); 404 401 405 402 HandleScope handle_scope; … … 409 406 return Undefined(); 410 407 411 const String::Utf8Value query(args[0]); 408 string query; 409 for (int i=0; i<args.Length(); i++) 410 query += string(" ") + *String::Utf8Value(args[i]); 411 query.erase(0, 1); 412 412 413 413 #ifdef HAVE_SQL … … 416 416 Database *db = reinterpret_cast<Database*>(ptr); 417 417 418 const mysqlpp::StoreQueryResult res = db->query( *query).store();418 const mysqlpp::StoreQueryResult res = db->query(query).store(); 419 419 420 420 Handle<Array> ret = Array::New(); 421 ret->Set(String::New("table"), String::New(res.table()), ReadOnly); 421 ret->Set(String::New("table"), String::New(res.table()), ReadOnly); 422 ret->Set(String::New("query"), String::New(query.c_str()), ReadOnly); 422 423 423 424 Handle<Array> cols = Array::New(); … … 434 435 const Handle<Value> name = String::New((*list)[i].c_str()); 435 436 if (irow==0) 436 cols->Set( Integer::NewFromUnsigned(i), name, ReadOnly);437 cols->Set(i, name); 437 438 438 439 if ((*it)[i].is_null()) … … 528 529 } 529 530 530 ret->Set( Integer::NewFromUnsigned(irow++), row, ReadOnly);531 ret->Set(irow++, row); 531 532 } 532 533 … … 546 547 { 547 548 if (args.Length()!=1) 548 return ThrowException(String::New("Number of arguments must be exactly1."));549 return ThrowException(String::New("Number of arguments must be 1.")); 549 550 550 551 if (!args[0]->IsString()) 551 return ThrowException(String::New("Argument 1 must be a string.")); 552 553 HandleScope handle_scope; 554 555 const String::Utf8Value database(args[0]); 556 const String::Utf8Value query (args[1]); 552 return ThrowException(String::New("Argument 1 not a string.")); 553 554 HandleScope handle_scope; 557 555 558 556 #ifdef HAVE_SQL 559 557 try 560 558 { 561 Database *db = new Database(* database);559 Database *db = new Database(*String::Utf8Value(args[0])); 562 560 fDatabases.push_back(db); 563 561 … … 1084 1082 } 1085 1083 1084 Handle<Value> InterpreterV8::LocalDist(const Arguments &args) 1085 { 1086 HandleScope handle_scope; 1087 1088 if (args.Length()!=2) 1089 return ThrowException(String::New("dist must not be called with two arguments.")); 1090 1091 if (!args[0]->IsObject() || !args[1]->IsObject()) 1092 return ThrowException(String::New("at least one argument not an object.")); 1093 1094 Handle<Object> obj[2] = 1095 { 1096 Handle<Object>::Cast(args[0]), 1097 Handle<Object>::Cast(args[1]) 1098 }; 1099 1100 const Handle<String> s_zd = String::New("zd"); 1101 const Handle<String> s_az = String::New("az"); 1102 1103 const double zd0 = obj[0]->Get(s_zd)->NumberValue() * M_PI/180; 1104 const double az0 = obj[0]->Get(s_az)->NumberValue() * M_PI/180; 1105 const double zd1 = obj[1]->Get(s_zd)->NumberValue() * M_PI/180; 1106 const double az1 = obj[1]->Get(s_az)->NumberValue() * M_PI/180; 1107 1108 if (!finite(zd0) || !finite(zd1) || !finite(az0) || !finite(az1)) 1109 return ThrowException(String::New("some values not valid or not finite.")); 1110 1111 /* 1112 const double x0 = sin(zd0) * cos(az0); // az0 -= az0 1113 const double y0 = sin(zd0) * sin(az0); // az0 -= az0 1114 const double z0 = cos(zd0); 1115 1116 const double x1 = sin(zd1) * cos(az1); // az1 -= az0 1117 const double y1 = sin(zd1) * sin(az1); // az1 -= az0 1118 const double z1 = cos(zd1); 1119 1120 const double res = acos(x0*x1 + y0*y1 + z0*z1) * 180/M_PI; 1121 */ 1122 1123 // cos(az1-az0) = cos(az1)*cos(az0) + sin(az1)*sin(az0) 1124 1125 const double x = sin(zd0) * sin(zd1) * cos(az1-az0); 1126 const double y = cos(zd0) * cos(zd1); 1127 1128 const double res = acos(x + y) * 180/M_PI; 1129 1130 return handle_scope.Close(Number::New(res)); 1131 } 1132 1086 1133 Handle<Value> InterpreterV8::MoonDisk(const Arguments &args) 1087 1134 { … … 1094 1141 const Time utc = args.Length()==0 ? Time() : Time(v/1000, v%1000); 1095 1142 1096 handle_scope.Close(Number::New(ln_get_lunar_disk(utc.JD())));1143 return handle_scope.Close(Number::New(ln_get_lunar_disk(utc.JD()))); 1097 1144 } 1098 1145 … … 1438 1485 1439 1486 Handle<FunctionTemplate> loc = FunctionTemplate::New(ConstructorLocal); 1487 loc->Set(String::New("dist"), FunctionTemplate::New(LocalDist), ReadOnly); 1440 1488 global->Set(String::New("Local"), loc, ReadOnly); 1441 1489 -
trunk/FACT++/src/InterpreterV8.h
r14578 r14591 72 72 static v8::Handle<v8::Value> ConstructLocal(double zd, double az, v8::Handle<v8::Value> time=v8::Handle<v8::Value>()); 73 73 static v8::Handle<v8::Value> ConstructSky(double ra, double dec, v8::Handle<v8::Value> time=v8::Handle<v8::Value>(), bool ismoon=false); 74 static v8::Handle<v8::Value> LocalDist(const v8::Arguments &args); 74 75 static v8::Handle<v8::Value> MoonDisk(const v8::Arguments &args); 75 76 static v8::Handle<v8::Value> LocalToSky(const v8::Arguments &args);
Note:
See TracChangeset
for help on using the changeset viewer.