Changeset 14059 for trunk/FACT++/src


Ignore:
Timestamp:
06/03/12 22:50:55 (12 years ago)
Author:
tbretz
Message:
Added special '$' array as arguments; moved sleep to dim-space; added state and name function template
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r14055 r14059  
    191191        return ThrowException(String::New("Argument 1 must be an uint32."));
    192192
    193     const HandleScope handle_scope;
    194 
    195193    JsSleep(args[0]->Int32Value());
    196194
    197195    return Undefined();
     196}
     197
     198Handle<Value> InterpreterV8::FuncState(const Arguments& args)
     199{
     200    if (args.Length()!=1)
     201        return ThrowException(String::New("Number of arguments must be exactly 1."));
     202
     203    if (!args[0]->IsString())
     204        return ThrowException(String::New("Argument 1 must be a string."));
     205
     206    const HandleScope handle_scope;
     207
     208    const String::Utf8Value str(args[0]);
     209    return Integer::New(JsState(*str));
     210}
     211
     212Handle<Value> InterpreterV8::FuncName(const Arguments& args)
     213{
     214    if (args.Length()!=1)
     215        return ThrowException(String::New("Number of arguments must be exactly 1."));
     216
     217    if (!args[0]->IsString())
     218        return ThrowException(String::New("Argument 1 must be a string."));
     219
     220    const HandleScope handle_scope;
     221
     222    const String::Utf8Value str(args[0]);
     223    return String::New(JsName(*str).c_str());
    198224}
    199225
     
    272298    dim->Set(String::New("wait"),    FunctionTemplate::New(WrapWait),    ReadOnly);
    273299    dim->Set(String::New("send"),    FunctionTemplate::New(WrapSend),    ReadOnly);
     300    dim->Set(String::New("state"),   FunctionTemplate::New(WrapState),   ReadOnly);
     301    dim->Set(String::New("name"),    FunctionTemplate::New(WrapName),    ReadOnly);
     302    dim->Set(String::New("sleep"),   FunctionTemplate::New(WrapSleep),   ReadOnly);
    274303
    275304    Handle<ObjectTemplate> global = ObjectTemplate::New();
    276305    global->Set(String::New("dim"), dim, ReadOnly);
    277306    global->Set(String::New("include"), FunctionTemplate::New(WrapInclude),                ReadOnly);
    278     global->Set(String::New("sleep"),   FunctionTemplate::New(WrapSleep),                  ReadOnly);
    279307    global->Set(String::New("exit"),    FunctionTemplate::New(WrapExit),                   ReadOnly);
    280308    global->Set(String::New("version"), FunctionTemplate::New(InterpreterV8::FuncVersion), ReadOnly);
     
    293321    for (auto it=map.begin(); it!=map.end(); it++)
    294322        args->Set(String::New(it->first.c_str()), String::New(it->second.c_str()));
     323    context->Global()->Set(String::New("$"),   args);
    295324    context->Global()->Set(String::New("arg"), args);
    296325
  • trunk/FACT++/src/InterpreterV8.h

    r14055 r14059  
    2828    v8::Handle<v8::Value> FuncInclude(const v8::Arguments& args);
    2929    v8::Handle<v8::Value> FuncExit(const v8::Arguments& args);
     30    v8::Handle<v8::Value> FuncState(const v8::Arguments& args);
     31    v8::Handle<v8::Value> FuncName(const v8::Arguments& args);
    3032
    3133    static v8::Handle<v8::Value> FuncVersion(const v8::Arguments&);
     
    3638    static v8::Handle<v8::Value> WrapSleep(const v8::Arguments &args)   { if (This) return This->FuncSleep(args);   else return v8::Undefined(); }
    3739    static v8::Handle<v8::Value> WrapExit(const v8::Arguments &args)    { if (This) return This->FuncExit(args);    else return v8::Undefined(); }
     40    static v8::Handle<v8::Value> WrapState(const v8::Arguments &args)   { if (This) return This->FuncState(args);   else return v8::Undefined(); }
     41    static v8::Handle<v8::Value> WrapName(const v8::Arguments &args)    { if (This) return This->FuncName(args);   else return v8::Undefined(); }
    3842#endif
    3943
     
    5862    virtual void JsSleep(uint32_t) { }
    5963    virtual int  JsWait(const std::string &, int32_t, uint32_t) { return -1; };
     64    virtual int  JsState(const std::string &) { return -3; };
     65    virtual std::string JsName(const std::string &) { return ""; };
    6066
    6167    bool JsRun(const std::string &, const std::map<std::string,std::string> & = std::map<std::string,std::string>());
Note: See TracChangeset for help on using the changeset viewer.