aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-05-03 00:45:09 +0400
committerIgor Pashev <pashev.igor@gmail.com>2012-05-03 00:45:09 +0400
commitbe250e243fab75b02de8985f9932adb79f1501aa (patch)
treec2341ae91b1ac5a9fbccf54280b8e219e58db997
parent4ede440972bd7800ed85f869e5679ea72815b78e (diff)
downloadnode-augeas-be250e243fab75b02de8985f9932adb79f1501aa.tar.gz
Allow passing options in object
-rw-r--r--libaugeas.cc34
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