diff options
| author | Igor Pashev <pashev.igor@gmail.com> | 2012-05-03 00:45:09 +0400 |
|---|---|---|
| committer | Igor Pashev <pashev.igor@gmail.com> | 2012-05-03 00:45:09 +0400 |
| commit | be250e243fab75b02de8985f9932adb79f1501aa (patch) | |
| tree | c2341ae91b1ac5a9fbccf54280b8e219e58db997 | |
| parent | 4ede440972bd7800ed85f869e5679ea72815b78e (diff) | |
| download | node-augeas-be250e243fab75b02de8985f9932adb79f1501aa.tar.gz | |
Allow passing options in object
| -rw-r--r-- | libaugeas.cc | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/libaugeas.cc b/libaugeas.cc index 0f82003..46300e6 100644 --- a/libaugeas.cc +++ b/libaugeas.cc @@ -223,20 +223,28 @@ Handle<Value> LibAugeas::New(const Arguments& args) std::string loadpath; unsigned int flags = 0; - if (args[0]->IsString()) { - String::Utf8Value p_str(args[0]); - root = *p_str; - } - if (args[1]->IsString()) { - String::Utf8Value l_str(args[1]); - loadpath = *l_str; - } - if (args[2]->IsNumber()) { - flags = args[2]->Int32Value(); + // Allow passing options in object: + if (args[0]->IsObject()) { + Local<Object> obj = args[0]->ToObject(); + root = memberToString(obj, "root"); + loadpath = memberToString(obj, "loadpath"); + flags = memberToUint32(obj, "flags"); + } else { + // C-like way: + if (args[0]->IsString()) { + String::Utf8Value p_str(args[0]); + root = *p_str; + } + if (args[1]->IsString()) { + String::Utf8Value l_str(args[1]); + loadpath = *l_str; + } + if (args[2]->IsNumber()) { + flags = args[2]->Uint32Value(); + } } - - obj->m_aug = aug_init(root.length() ? root.c_str() : NULL, - loadpath.length() ? loadpath.c_str() : NULL, flags); + + obj->m_aug = aug_init(root.c_str(), loadpath.c_str(), flags); /* * If flags have AUG_NO_ERR_CLOSE aug_init() might return non-null |
