diff --git a/doc/20-library-reference.md b/doc/20-library-reference.md
index 6b78192d2..b3ed5b8de 100644
--- a/doc/20-library-reference.md
+++ b/doc/20-library-reference.md
@@ -554,6 +554,14 @@ Signature:
Sets the element at the zero-based index to the specified value. The `index` must refer to an element
which already exists in the array.
+### Array#get
+
+Signature:
+
+ function get(index);
+
+Retrieves the element at the specified zero-based index.
+
### Array#sort
Signature:
@@ -616,6 +624,15 @@ Signature:
Creates or updates an item with the specified `key` and `value`.
+### Dictionary#get
+
+Signature:
+
+ function get(key);
+
+Retrieves the value for the specified `key`. Returns `null` if they `key` does not exist
+in the dictionary.
+
## Function type
### Function#call
diff --git a/lib/base/array-script.cpp b/lib/base/array-script.cpp
index 6118d11b4..625c476f1 100644
--- a/lib/base/array-script.cpp
+++ b/lib/base/array-script.cpp
@@ -40,6 +40,13 @@ static void ArraySet(int index, const Value& value)
self->Set(index, value);
}
+static Value ArrayGet(int index)
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ Array::Ptr self = static_cast(vframe->Self);
+ return self->Get(index);
+}
+
static void ArrayAdd(const Value& value)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
@@ -131,6 +138,7 @@ Object::Ptr Array::GetPrototype(void)
prototype = new Dictionary();
prototype->Set("len", new Function(WrapFunction(ArrayLen)));
prototype->Set("set", new Function(WrapFunction(ArraySet)));
+ prototype->Set("get", new Function(WrapFunction(ArrayGet)));
prototype->Set("add", new Function(WrapFunction(ArrayAdd)));
prototype->Set("remove", new Function(WrapFunction(ArrayRemove)));
prototype->Set("contains", new Function(WrapFunction(ArrayContains)));
diff --git a/lib/base/dictionary-script.cpp b/lib/base/dictionary-script.cpp
index 3834e39fc..b10be389d 100644
--- a/lib/base/dictionary-script.cpp
+++ b/lib/base/dictionary-script.cpp
@@ -38,6 +38,13 @@ static void DictionarySet(const String& key, const Value& value)
self->Set(key, value);
}
+static Value DictionaryGet(const String& key)
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ Dictionary::Ptr self = static_cast(vframe->Self);
+ return self->Get(key);
+}
+
static void DictionaryRemove(const String& key)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
@@ -67,6 +74,7 @@ Object::Ptr Dictionary::GetPrototype(void)
prototype = new Dictionary();
prototype->Set("len", new Function(WrapFunction(DictionaryLen)));
prototype->Set("set", new Function(WrapFunction(DictionarySet)));
+ prototype->Set("get", new Function(WrapFunction(DictionaryGet)));
prototype->Set("remove", new Function(WrapFunction(DictionaryRemove)));
prototype->Set("contains", new Function(WrapFunction(DictionaryContains)));
prototype->Set("clone", new Function(WrapFunction(DictionaryClone)));