Ignore:
Timestamp:
06/08/12 22:01:56 (12 years ago)
Author:
tbretz
Message:
Added a function dim.out which will only print to the local console; improved conversion from dim service elements to ECMA numbers
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/InterpreterV8.cc

    r14125 r14135  
    257257}
    258258
     259Handle<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
    259272// The callback that is invoked by v8 whenever the JavaScript 'load'
    260273// function is called.  Loads, compiles and executes its argument
     
    283296Handle<Value> Convert(char type, const char* &ptr)
    284297{
     298    // Dim values are always unsigned per (FACT++) definition
    285299    switch (type)
    286300    {
    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; }
    294324    case ':':  { Handle<Value> v=String::New(ptr); return v; }
    295325    }
     
    448478    Handle<ObjectTemplate> dim = ObjectTemplate::New();
    449479    dim->Set(String::New("print"),   FunctionTemplate::New(WrapPrint), ReadOnly);
     480    dim->Set(String::New("out"),     FunctionTemplate::New(WrapOut),   ReadOnly);
    450481    dim->Set(String::New("wait"),    FunctionTemplate::New(WrapWait),  ReadOnly);
    451482    dim->Set(String::New("send"),    FunctionTemplate::New(WrapSend),  ReadOnly);
     
    486517    //context.Dispose();
    487518
    488     cout << "JsEnd" << endl;
    489519    JsEnd(filename);
    490520
Note: See TracChangeset for help on using the changeset viewer.