Changeset 14135
- Timestamp:
- 06/08/12 22:01:56 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14125 r14135 257 257 } 258 258 259 Handle<Value> InterpreterV8::FuncOut(const Arguments& args) 260 { 261 for (int i=0; i<args.Length(); i++) 262 { 263 const HandleScope handle_scope; 264 265 const String::Utf8Value str(args[i]); 266 if (*str) 267 JsOut(*str); 268 } 269 return Undefined(); 270 } 271 259 272 // The callback that is invoked by v8 whenever the JavaScript 'load' 260 273 // function is called. Loads, compiles and executes its argument … … 283 296 Handle<Value> Convert(char type, const char* &ptr) 284 297 { 298 // Dim values are always unsigned per (FACT++) definition 285 299 switch (type) 286 300 { 287 case 'F': { Handle<Value> v=Number::New(*reinterpret_cast<const float*>(ptr)); ptr+=4; return v; } 288 case 'D': { Handle<Value> v=Number::New(*reinterpret_cast<const double*>(ptr)); ptr+=8; return v; } 289 case 'I': { 290 case 'L': Handle<Value> v=Integer::New(*reinterpret_cast<const uint32_t*>(ptr)); ptr += 4; return v; } 291 case 'X': { Handle<Value> v=Integer::New(*reinterpret_cast<const uint64_t*>(ptr)); ptr += 8; return v; } 292 case 'S': { Handle<Value> v=Integer::New(*reinterpret_cast<const uint16_t*>(ptr)); ptr += 2; return v; } 293 case 'C': { Handle<Value> v=Integer::New((uint16_t)*reinterpret_cast<const uint8_t*>(ptr)); ptr += 1; return v; } 301 case 'F': 302 { 303 // Remove the "imprecision" effect coming from casting a float to 304 // a double and then showing it with double precision 305 ostringstream val; 306 val << setprecision(7) << *reinterpret_cast<const float*>(ptr); 307 Handle<Value> v=Number::New(stod(val.str())); 308 ptr+=4; 309 return v; 310 } 311 case 'D': { Handle<Value> v=Number::New(*reinterpret_cast<const double*>(ptr)); ptr+=8; return v; } 312 case 'I': 313 case 'L': { Handle<Value> v=Integer::NewFromUnsigned(*reinterpret_cast<const uint32_t*>(ptr)); ptr += 4; return v; } 314 case 'X': 315 { 316 const uint64_t val = *reinterpret_cast<const uint64_t*>(ptr); 317 ptr += 8; 318 if (val>UINT32_MAX) 319 return Number::New(val); 320 return Integer::NewFromUnsigned(val); 321 } 322 case 'S': { Handle<Value> v=Integer::NewFromUnsigned(*reinterpret_cast<const uint16_t*>(ptr)); ptr += 2; return v; } 323 case 'C': { Handle<Value> v=Integer::NewFromUnsigned((uint16_t)*reinterpret_cast<const uint8_t*>(ptr)); ptr += 1; return v; } 294 324 case ':': { Handle<Value> v=String::New(ptr); return v; } 295 325 } … … 448 478 Handle<ObjectTemplate> dim = ObjectTemplate::New(); 449 479 dim->Set(String::New("print"), FunctionTemplate::New(WrapPrint), ReadOnly); 480 dim->Set(String::New("out"), FunctionTemplate::New(WrapOut), ReadOnly); 450 481 dim->Set(String::New("wait"), FunctionTemplate::New(WrapWait), ReadOnly); 451 482 dim->Set(String::New("send"), FunctionTemplate::New(WrapSend), ReadOnly); … … 486 517 //context.Dispose(); 487 518 488 cout << "JsEnd" << endl;489 519 JsEnd(filename); 490 520 -
trunk/FACT++/src/InterpreterV8.h
r14133 r14135 29 29 v8::Handle<v8::Value> FuncSleep(const v8::Arguments& args); 30 30 v8::Handle<v8::Value> FuncPrint(const v8::Arguments& args); 31 v8::Handle<v8::Value> FuncOut(const v8::Arguments& args); 31 32 v8::Handle<v8::Value> FuncInclude(const v8::Arguments& args); 32 33 v8::Handle<v8::Value> FuncExit(const v8::Arguments& args); … … 39 40 static v8::Handle<v8::Value> WrapInclude(const v8::Arguments &args) { if (This) return This->FuncInclude(args); else return v8::Undefined(); } 40 41 static v8::Handle<v8::Value> WrapPrint(const v8::Arguments &args) { if (This) return This->FuncPrint(args); else return v8::Undefined(); } 42 static v8::Handle<v8::Value> WrapOut(const v8::Arguments &args) { if (This) return This->FuncOut(args); else return v8::Undefined(); } 41 43 static v8::Handle<v8::Value> WrapWait(const v8::Arguments &args) { if (This) return This->FuncWait(args); else return v8::Undefined(); } 42 44 static v8::Handle<v8::Value> WrapSend(const v8::Arguments &args) { if (This) return This->FuncSend(args); else return v8::Undefined(); } … … 66 68 virtual void JsEnd(const std::string &) { } 67 69 virtual void JsPrint(const std::string &) { } 70 virtual void JsOut(const std::string &) { } 68 71 virtual void JsResult(const std::string &) { } 69 72 virtual void JsException(const std::string &) { } -
trunk/FACT++/src/RemoteControl.h
r14126 r14135 165 165 virtual void JsEnd(const std::string &) { UnsubscribeAll(); SetSection(-3); } 166 166 virtual bool JsSend(const std::string &str) { return ProcessCommand(str); } 167 virtual void JsOut(const std::string &msg) { lout << msg << endl; } 167 168 virtual void JsPrint(const std::string &msg) { if (fImp) fImp->Comment(msg.empty()?" ":msg); } 168 169 virtual void JsException(const std::string &str) { if (fImp) fImp->Error(str.empty()?" ":str); }
Note:
See TracChangeset
for help on using the changeset viewer.